Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
perf: avoid infinite enhancer loops
Browse files Browse the repository at this point in the history
  • Loading branch information
marionebl committed Sep 10, 2018
1 parent a00ba8a commit 0c33f71
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
24 changes: 19 additions & 5 deletions src/container/pane-development-editor.tsx
Expand Up @@ -55,24 +55,38 @@ export class PaneDevelopmentEditor extends React.Component {
});

this.editor.onDidChangeModelContent(async () => {
storeEnhancer.setTypeScript(this.editor.getValue());
const value = this.editor.getValue();
storeEnhancer.setTypeScript(value);

const model = this.editor.getModel();
const worker = await Monaco.languages.typescript.getTypeScriptWorker();
const client = await worker(model.uri);
const getClient = await Monaco.languages.typescript.getTypeScriptWorker();
const client = await getClient(model.uri);
const emitOutput = await client.getEmitOutput(model.uri.toString());

const outputFile = emitOutput.outputFiles.find(
file => file.name === `${model.uri.toString()}.js`
);

if (outputFile) {
console.log(outputFile.text);
storeEnhancer.setJavaScript(outputFile.text);
}
});

this.editor.onDidBlurEditor(() => {
this.editor.onDidBlurEditor(async () => {
storeEnhancer.setTypeScript(this.editor.getValue());

const model = this.editor.getModel();
const getClient = await Monaco.languages.typescript.getTypeScriptWorker();
const client = await getClient(model.uri);
const emitOutput = await client.getEmitOutput(model.uri.toString());
const outputFile = emitOutput.outputFiles.find(
file => file.name === `${model.uri.toString()}.js`
);

if (outputFile) {
storeEnhancer.setJavaScript(outputFile.text);
}

props.store.commit();
});

Expand Down
13 changes: 1 addition & 12 deletions src/model/user-store-enhancer.ts
Expand Up @@ -93,18 +93,6 @@ export class UserStoreEnhancer {
@Mobx.observable private typeScript: string;
@Mobx.observable private javaScript: string;

// @Mobx.computed
// private get js(): string {
// const fs = new MemoryFilesystem();
// fs.writeFileSync('/file.ts', this.code);
// compile('/file.ts', {
// compilerOptions: {},
// fs,
// languageVersion: TypeScript.ScriptTarget.ESNext
// });
// return String(fs.readFileSync('/file.js'));
// }

@Mobx.computed
private get module(): UserStoreEnhancerModule {
const context = { exports: {}, module: { exports: {} }, console };
Expand Down Expand Up @@ -171,5 +159,6 @@ export class UserStoreEnhancer {

public update(b: this): void {
this.typeScript = b.typeScript;
this.javaScript = b.javaScript;
}
}
2 changes: 1 addition & 1 deletion src/renderer/create-project-message-handler.ts
Expand Up @@ -109,7 +109,7 @@ export function createProjectMessageHandler({
break;
}
case Message.MessageType.ChangeUserStore: {
project.getUserStore().sync(message);
project.getUserStore().sync(message, { withEnhancer: false });
break;
}
case Message.MessageType.SelectElement: {
Expand Down

0 comments on commit 0c33f71

Please sign in to comment.