mirror of
https://github.com/wickedest/Mergely.git
synced 2026-04-21 12:02:37 +08:00
chore: start of a webworker
This commit is contained in:
@@ -55,7 +55,8 @@
|
||||
"style-loader": "^2.0.0",
|
||||
"webpack": "^4.44.2",
|
||||
"webpack-cli": "^4.0.0",
|
||||
"webpack-dev-server": "^3.11.0"
|
||||
"webpack-dev-server": "^3.11.0",
|
||||
"worker-loader": "^3.0.8"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "npm run test && npm run build:dist",
|
||||
|
||||
@@ -993,10 +993,27 @@ CodeMirrorDiffView.prototype._diff = function() {
|
||||
}
|
||||
const lhs = this.editor.lhs.getValue();
|
||||
const rhs = this.editor.rhs.getValue();
|
||||
const comparison = new diff(lhs, rhs, this.settings);
|
||||
this.changes = DiffParser(comparison.normal_form());
|
||||
if (this.settings._debug.includes('change')) {
|
||||
traceTimeEnd(' change#_diff');
|
||||
/*
|
||||
if (window.Worker) {
|
||||
if (!this._diffWorker) {
|
||||
trace(' change#_diff creating diff worker');
|
||||
// this._diffWorker = new Worker('./diff-worker.js');
|
||||
this._diffWorker = new Worker(new URL('./diff-worker.js', import.meta.url));
|
||||
this._diffWorker.onchange = (ev) => {
|
||||
this.changes = ev.data;
|
||||
this._clear();
|
||||
this._changed();
|
||||
}
|
||||
}
|
||||
trace(' change#_diff starting worker');
|
||||
this._diffWorker.postMessage({ lhs, rhs });
|
||||
} else
|
||||
*/{
|
||||
const comparison = new diff(lhs, rhs, this.settings);
|
||||
this.changes = DiffParser(comparison.normal_form());
|
||||
if (this.settings._debug.includes('change')) {
|
||||
traceTimeEnd(' change#_diff');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
8
src/diff-worker.js
Normal file
8
src/diff-worker.js
Normal file
@@ -0,0 +1,8 @@
|
||||
const diff = require('./diff');
|
||||
|
||||
onmessage = function (ev) {
|
||||
const { lhs, rhs } = ev;
|
||||
const compare = new diff(lhs, rhs, this.settings);
|
||||
const changes = DiffParser(compare.normal_form());
|
||||
postMessage(changes);
|
||||
};
|
||||
@@ -23,6 +23,11 @@ module.exports = {
|
||||
}, {
|
||||
loader: 'css-loader'
|
||||
}]
|
||||
}, {
|
||||
test: /worker\.js$/,
|
||||
use: {
|
||||
loader: 'worker-loader'
|
||||
}
|
||||
}]
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user