Skip to content

Commit 773d572

Browse files
committed
move preload to Editor service
1 parent 17dfdef commit 773d572

2 files changed

Lines changed: 23 additions & 14 deletions

File tree

src/CodeEditor/rx/editor.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,10 @@ export const editorRx = Rx.family((workspace: Workspace) => {
2222
workspaceHandleRx(workspace)
2323
)
2424
const el = yield* get.some(element)
25-
const { monaco } = yield* Monaco
26-
const { makeEditorWithATA } = yield* MonacoATA
27-
const editor = yield* makeEditorWithATA(el)
25+
const monaco = yield* MonacoATA
26+
const editor = yield* monaco.makeEditorWithATA(el)
2827

29-
yield* Effect.forEach(workspace.filePaths, ([file, path]) => {
30-
if (file.language === "typescript") {
31-
const uri = monaco.Uri.parse(path)
32-
if (monaco.editor.getModel(uri) === null) {
33-
monaco.editor.createModel(file.initialContent, file.language, uri)
34-
}
35-
}
36-
return Effect.void
37-
})
28+
yield* editor.preload(workspace)
3829

3930
get.subscribe(
4031
editorThemeRx,

src/CodeEditor/services/Monaco.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { File } from "@/domain/Workspace"
1+
import { File, Workspace } from "@/domain/Workspace"
22
import { Data, Effect, GlobalValue, Layer, Stream } from "effect"
33
import * as monaco from "monaco-editor/esm/vs/editor/editor.api"
44

@@ -97,14 +97,32 @@ const make = Effect.gen(function* () {
9797
return model
9898
})
9999

100+
const preload = (workspace: Workspace) =>
101+
Effect.forEach(
102+
workspace.filePaths,
103+
([file, path]) =>
104+
Effect.sync(() => {
105+
const uri = monaco.Uri.parse(path)
106+
if (monaco.editor.getModel(uri)) {
107+
return
108+
}
109+
monaco.editor.createModel(
110+
file.initialContent,
111+
file.language,
112+
uri
113+
)
114+
}),
115+
{ discard: true }
116+
)
117+
100118
const content = Stream.async<string>((emit) => {
101119
const cancel = editor.onDidChangeModelContent(() => {
102120
emit.single(editor.getValue())
103121
})
104122
return Effect.sync(() => cancel.dispose())
105123
})
106124

107-
return { editor, load, content, theme } as const
125+
return { editor, load, preload, content, theme } as const
108126
})
109127

110128
function listen<A>(event: monaco.IEvent<A>) {

0 commit comments

Comments
 (0)