Skip to content

Commit c83d923

Browse files
authored
separate state updates from file updates (sveltejs#597)
1 parent f88b697 commit c83d923

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

packages/editor/src/lib/Workspace.svelte.ts

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -315,31 +315,12 @@ export class Workspace {
315315
}
316316

317317
update_file(file: File) {
318-
if (file.name === this.#current.name) {
319-
this.#current = file;
320-
}
321-
322-
this.#files = this.#files.map((old) => {
323-
if (old.name === file.name) {
324-
return file;
325-
}
326-
return old;
327-
});
328-
329-
this.modified[file.name] = true;
330-
331-
if (BROWSER && is_svelte_file(file)) {
332-
compile_file(file, this.#svelte_version, this.compiler_options).then((compiled) => {
333-
this.compiled[file.name] = compiled;
334-
});
335-
}
318+
this.#update_file(file);
336319

337320
const state = this.states.get(file.name);
338321
if (state) {
339322
this.#update_state(file, state);
340323
}
341-
342-
this.#onupdate(file);
343324
}
344325

345326
#create_directories(item: Item) {
@@ -374,7 +355,7 @@ export class Workspace {
374355
if (update.docChanged) {
375356
const state = this.#view!.state!;
376357

377-
this.update_file({
358+
this.#update_file({
378359
...this.#current,
379360
contents: state.doc.toString()
380361
});
@@ -461,6 +442,29 @@ export class Workspace {
461442
this.#view?.setState(this.#get_state(this.#current));
462443
}
463444

445+
#update_file(file: File) {
446+
if (file.name === this.#current.name) {
447+
this.#current = file;
448+
}
449+
450+
this.#files = this.#files.map((old) => {
451+
if (old.name === file.name) {
452+
return file;
453+
}
454+
return old;
455+
});
456+
457+
this.modified[file.name] = true;
458+
459+
if (BROWSER && is_svelte_file(file)) {
460+
compile_file(file, this.#svelte_version, this.compiler_options).then((compiled) => {
461+
this.compiled[file.name] = compiled;
462+
});
463+
}
464+
465+
this.#onupdate(file);
466+
}
467+
464468
#update_state(file: File, state: EditorState) {
465469
const existing = state.doc.toString();
466470

0 commit comments

Comments
 (0)