Commit fd818194 authored by Phil Hughes's avatar Phil Hughes

fixed web worker performance

[ci skip]
parent 3a1c3c5d
......@@ -35,7 +35,7 @@ export default {
this.editor.createInstance(this.$el);
})
.then(() => this.setupEditor())
.catch((e) => { throw e;flash('Error setting up monaco. Please try again.'); });
.catch(() => flash('Error setting up monaco. Please try again.'));
},
setupEditor() {
if (!this.activeFile) return;
......
/* global monaco */
import DirtyDiffWorker from 'worker-loader!./worker.diff';
import { throttle } from 'underscore';
import DirtyDiffWorker from './diff_worker';
import Disposable from '../common/disposable';
export const getDiffChangeType = (change) => {
......@@ -34,12 +35,14 @@ export default class DirtyDiffController {
this.modelManager = modelManager;
this.decorationsController = decorationsController;
this.dirtyDiffWorker = new DirtyDiffWorker();
this.throttledComputeDiff = throttle(this.computeDiff, 250);
this.decorate = this.decorate.bind(this);
this.dirtyDiffWorker.addEventListener('message', e => this.decorate(e));
this.dirtyDiffWorker.addEventListener('message', this.decorate);
}
attachModel(model) {
model.onChange(() => this.computeDiff(model));
model.onChange(() => this.throttledComputeDiff(model));
}
computeDiff(model) {
......@@ -61,6 +64,8 @@ export default class DirtyDiffController {
dispose() {
this.disposable.dispose();
this.dirtyDiffWorker.removeEventListener('message', this.decorate);
this.dirtyDiffWorker.terminate();
}
}
import { diffLines } from 'diff';
// eslint-disable-next-line import/prefer-default-export
export const computeDiff = (originalContent, newContent) => {
const changes = diffLines(originalContent, newContent);
......
......@@ -116,6 +116,10 @@ var config = {
loader: 'url-loader',
options: { limit: 2048 },
},
{
test: /\_worker\.js$/,
loader: 'worker-loader',
},
{
test: /\.(worker(\.min)?\.js|pdf|bmpr)$/,
exclude: /node_modules/,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment