Skip to content

Commit

Permalink
separate state updates from file updates (sveltejs#597)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris authored Oct 23, 2024
1 parent f88b697 commit c83d923
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions packages/editor/src/lib/Workspace.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,31 +315,12 @@ export class Workspace {
}

update_file(file: File) {
if (file.name === this.#current.name) {
this.#current = file;
}

this.#files = this.#files.map((old) => {
if (old.name === file.name) {
return file;
}
return old;
});

this.modified[file.name] = true;

if (BROWSER && is_svelte_file(file)) {
compile_file(file, this.#svelte_version, this.compiler_options).then((compiled) => {
this.compiled[file.name] = compiled;
});
}
this.#update_file(file);

const state = this.states.get(file.name);
if (state) {
this.#update_state(file, state);
}

this.#onupdate(file);
}

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

this.update_file({
this.#update_file({
...this.#current,
contents: state.doc.toString()
});
Expand Down Expand Up @@ -461,6 +442,29 @@ export class Workspace {
this.#view?.setState(this.#get_state(this.#current));
}

#update_file(file: File) {
if (file.name === this.#current.name) {
this.#current = file;
}

this.#files = this.#files.map((old) => {
if (old.name === file.name) {
return file;
}
return old;
});

this.modified[file.name] = true;

if (BROWSER && is_svelte_file(file)) {
compile_file(file, this.#svelte_version, this.compiler_options).then((compiled) => {
this.compiled[file.name] = compiled;
});
}

this.#onupdate(file);
}

#update_state(file: File, state: EditorState) {
const existing = state.doc.toString();

Expand Down

0 comments on commit c83d923

Please sign in to comment.