Commit 3a1c3c5d authored by Phil Hughes's avatar Phil Hughes

added web worker to calculate diffs

[ci skip]
parent 809a27e6
/* global monaco */ /* global monaco */
import DirtyDiffWorker from './diff'; import DirtyDiffWorker from 'worker-loader!./worker.diff';
console.log(DirtyDiffWorker);
import Disposable from '../common/disposable'; import Disposable from '../common/disposable';
export const getDiffChangeType = (change) => { export const getDiffChangeType = (change) => {
...@@ -34,8 +33,9 @@ export default class DirtyDiffController { ...@@ -34,8 +33,9 @@ export default class DirtyDiffController {
this.editorSimpleWorker = null; this.editorSimpleWorker = null;
this.modelManager = modelManager; this.modelManager = modelManager;
this.decorationsController = decorationsController; this.decorationsController = decorationsController;
console.log(DirtyDiffWorker); this.dirtyDiffWorker = new DirtyDiffWorker();
// this.dirtyDiffWorker = new DirtyDiffWorker();
this.dirtyDiffWorker.addEventListener('message', e => this.decorate(e));
} }
attachModel(model) { attachModel(model) {
...@@ -43,20 +43,24 @@ export default class DirtyDiffController { ...@@ -43,20 +43,24 @@ export default class DirtyDiffController {
} }
computeDiff(model) { computeDiff(model) {
this.decorate(model, this.dirtyDiffWorker.compute(model)); this.dirtyDiffWorker.postMessage({
path: model.path,
originalContent: model.getOriginalModel().getValue(),
newContent: model.getModel().getValue(),
});
} }
// eslint-disable-next-line class-methods-use-this
reDecorate(model) { reDecorate(model) {
this.decorationsController.decorate(model); this.decorationsController.decorate(model);
} }
decorate(model, changes) { decorate({ data }) {
const decorations = changes.map(change => getDecorator(change)); const decorations = data.changes.map(change => getDecorator(change));
this.decorationsController.addDecorations(model, 'dirtyDiff', decorations); this.decorationsController.addDecorations(data.path, 'dirtyDiff', decorations);
} }
dispose() { dispose() {
this.disposable.dispose(); this.disposable.dispose();
this.dirtyDiffWorker.terminate();
} }
} }
import { diffLines } from 'diff'; import { diffLines } from 'diff';
// export default class DirtyDiffWorker { export const computeDiff = (originalContent, newContent) => {
// // eslint-disable-next-line class-methods-use-this const changes = diffLines(originalContent, newContent);
// compute(model) {
// console.time('a'); let lineNumber = 1;
// const originalContent = model.getOriginalModel().getValue(); return changes.reduce((acc, change) => {
// const newContent = model.getModel().getValue(); const findOnLine = acc.find(c => c.lineNumber === lineNumber);
// const changes = diffLines(originalContent, newContent);
// if (findOnLine) {
// let lineNumber = 1; Object.assign(findOnLine, change, {
// const a = changes.reduce((acc, change) => { modified: true,
// const findOnLine = acc.find(c => c.lineNumber === lineNumber); endLineNumber: (lineNumber + change.count) - 1,
// });
// if (findOnLine) { } else if ('added' in change || 'removed' in change) {
// Object.assign(findOnLine, change, { acc.push(Object.assign({}, change, {
// modified: true, lineNumber,
// endLineNumber: (lineNumber + change.count) - 1, modified: undefined,
// }); endLineNumber: (lineNumber + change.count) - 1,
// } else if ('added' in change || 'removed' in change) { }));
// acc.push(Object.assign({}, change, { }
// lineNumber,
// modified: undefined, if (!change.removed) {
// endLineNumber: (lineNumber + change.count) - 1, lineNumber += change.count;
// })); }
// }
// return acc;
// if (!change.removed) { }, []);
// lineNumber += change.count; };
// }
//
// return acc;
// }, []);
// console.timeEnd('a');
//
// return a;
// }
// }
import { computeDiff } from './diff';
self.addEventListener('message', (e) => {
const data = e.data;
self.postMessage({
path: data.path,
changes: computeDiff(data.originalContent, data.newContent),
});
});
...@@ -116,6 +116,15 @@ ajv@^4.7.0, ajv@^4.9.1: ...@@ -116,6 +116,15 @@ ajv@^4.7.0, ajv@^4.9.1:
co "^4.6.0" co "^4.6.0"
json-stable-stringify "^1.0.1" json-stable-stringify "^1.0.1"
ajv@^5.0.0:
version "5.4.0"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-5.4.0.tgz#32d1cf08dbc80c432f426f12e10b2511f6b46474"
dependencies:
co "^4.6.0"
fast-deep-equal "^1.0.0"
fast-json-stable-stringify "^2.0.0"
json-schema-traverse "^0.3.0"
ajv@^5.1.5: ajv@^5.1.5:
version "5.2.2" version "5.2.2"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-5.2.2.tgz#47c68d69e86f5d953103b0074a9430dc63da5e39" resolved "https://registry.yarnpkg.com/ajv/-/ajv-5.2.2.tgz#47c68d69e86f5d953103b0074a9430dc63da5e39"
...@@ -2531,6 +2540,10 @@ fast-deep-equal@^1.0.0: ...@@ -2531,6 +2540,10 @@ fast-deep-equal@^1.0.0:
version "1.0.0" version "1.0.0"
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-1.0.0.tgz#96256a3bc975595eb36d82e9929d060d893439ff" resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-1.0.0.tgz#96256a3bc975595eb36d82e9929d060d893439ff"
fast-json-stable-stringify@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz#d5142c0caee6b1189f87d3a76111064f86c8bbf2"
fast-levenshtein@~2.0.4: fast-levenshtein@~2.0.4:
version "2.0.6" version "2.0.6"
resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917" resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917"
...@@ -3847,7 +3860,7 @@ loader-utils@^0.2.15, loader-utils@^0.2.5: ...@@ -3847,7 +3860,7 @@ loader-utils@^0.2.15, loader-utils@^0.2.5:
json5 "^0.5.0" json5 "^0.5.0"
object-assign "^4.0.1" object-assign "^4.0.1"
loader-utils@^1.0.2, loader-utils@^1.1.0: loader-utils@^1.0.0, loader-utils@^1.0.2, loader-utils@^1.1.0:
version "1.1.0" version "1.1.0"
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-1.1.0.tgz#c98aef488bcceda2ffb5e2de646d6a754429f5cd" resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-1.1.0.tgz#c98aef488bcceda2ffb5e2de646d6a754429f5cd"
dependencies: dependencies:
...@@ -5538,6 +5551,12 @@ sax@~1.2.1: ...@@ -5538,6 +5551,12 @@ sax@~1.2.1:
version "1.2.2" version "1.2.2"
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.2.tgz#fd8631a23bc7826bef5d871bdb87378c95647828" resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.2.tgz#fd8631a23bc7826bef5d871bdb87378c95647828"
schema-utils@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-0.3.0.tgz#f5877222ce3e931edae039f17eb3716e7137f8cf"
dependencies:
ajv "^5.0.0"
select-hose@^2.0.0: select-hose@^2.0.0:
version "2.0.0" version "2.0.0"
resolved "https://registry.yarnpkg.com/select-hose/-/select-hose-2.0.0.tgz#625d8658f865af43ec962bfc376a37359a4994ca" resolved "https://registry.yarnpkg.com/select-hose/-/select-hose-2.0.0.tgz#625d8658f865af43ec962bfc376a37359a4994ca"
...@@ -6605,6 +6624,13 @@ wordwrap@~0.0.2: ...@@ -6605,6 +6624,13 @@ wordwrap@~0.0.2:
version "0.0.3" version "0.0.3"
resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-0.0.3.tgz#a3d5da6cd5c0bc0008d37234bbaf1bed63059107" resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-0.0.3.tgz#a3d5da6cd5c0bc0008d37234bbaf1bed63059107"
worker-loader@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/worker-loader/-/worker-loader-1.1.0.tgz#8cf21869a07add84d66f821d948d23c1eb98e809"
dependencies:
loader-utils "^1.0.0"
schema-utils "^0.3.0"
wrap-ansi@^2.0.0: wrap-ansi@^2.0.0:
version "2.1.0" version "2.1.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-2.1.0.tgz#d8fc3d284dd05794fe84973caecdd1cf824fdd85" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-2.1.0.tgz#d8fc3d284dd05794fe84973caecdd1cf824fdd85"
......
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