Skip to content

Commit

Permalink
model.dispose()
Browse files Browse the repository at this point in the history
  • Loading branch information
abentkamp committed Nov 28, 2023
1 parent 374afa3 commit 244c373
Showing 1 changed file with 1 addition and 25 deletions.
26 changes: 1 addition & 25 deletions client/src/components/level.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ function Level() {
const params = useParams()
const levelId = parseInt(params.levelId)
const worldId = params.worldId
// useLoadWorldFiles(worldId)

const [impressum, setImpressum] = React.useState(false)

Expand Down Expand Up @@ -615,6 +614,7 @@ function useLevelEditor(codeviewRef, initialCode, initialSelections, onDidChange

return () => {
editorConnection.api.sendClientNotification(uriStr, "textDocument/didClose", {textDocument: {uri: uriStr}})
model.dispose();
}
}
}, [editor, levelId, connection, leanClientStarted])
Expand All @@ -637,27 +637,3 @@ function useLevelEditor(codeviewRef, initialCode, initialSelections, onDidChange

return {editor, infoProvider, editorConnection}
}

/** Open all files in this world on the server so that they will load faster when accessed */
function useLoadWorldFiles(worldId) {
const gameId = React.useContext(GameIdContext)
const gameInfo = useGetGameInfoQuery({game: gameId})
const store = useStore()

useEffect(() => {
if (gameInfo.data) {
const models = []
for (let levelId = 1; levelId <= gameInfo.data.worldSize[worldId]; levelId++) {
const uri = monaco.Uri.parse(`file:///${worldId}/${levelId}`)
let model = monaco.editor.getModel(uri)
if (model) {
models.push(model)
} else {
const code = selectCode(gameId, worldId, levelId)(store.getState())
models.push(monaco.editor.createModel(code, 'lean4', uri))
}
}
return () => { for (let model of models) { model.dispose() } }
}
}, [gameInfo.data, worldId])
}

0 comments on commit 244c373

Please sign in to comment.