forked from benjamine/jsondiffpatch
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdiffpatcher.js
More file actions
78 lines (70 loc) · 1.98 KB
/
diffpatcher.js
File metadata and controls
78 lines (70 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import Processor from './processor.js';
import Pipe from './pipe.js';
import DiffContext from './contexts/diff.js';
import PatchContext from './contexts/patch.js';
import ReverseContext from './contexts/reverse.js';
import clone from './clone.js';
import * as trivial from './filters/trivial.js';
import * as nested from './filters/nested.js';
import * as arrays from './filters/arrays.js';
import * as dates from './filters/dates.js';
import * as texts from './filters/texts.js';
export default class DiffPatcher {
constructor(options) {
this.processor = new Processor(options);
this.processor.pipe(
new Pipe('diff')
.append(
nested.collectChildrenDiffFilter,
trivial.diffFilter,
dates.diffFilter,
texts.diffFilter,
nested.objectsDiffFilter,
arrays.diffFilter
)
.shouldHaveResult()
);
this.processor.pipe(
new Pipe('patch')
.append(
nested.collectChildrenPatchFilter,
arrays.collectChildrenPatchFilter,
trivial.patchFilter,
texts.patchFilter,
nested.patchFilter,
arrays.patchFilter
)
.shouldHaveResult()
);
this.processor.pipe(
new Pipe('reverse')
.append(
nested.collectChildrenReverseFilter,
arrays.collectChildrenReverseFilter,
trivial.reverseFilter,
texts.reverseFilter,
nested.reverseFilter,
arrays.reverseFilter
)
.shouldHaveResult()
);
}
options(...args) {
return this.processor.options(...args);
}
diff(left, right) {
return this.processor.process(new DiffContext(left, right));
}
patch(left, delta) {
return this.processor.process(new PatchContext(left, delta));
}
reverse(delta) {
return this.processor.process(new ReverseContext(delta));
}
unpatch(right, delta) {
return this.patch(right, this.reverse(delta));
}
clone(value) {
return clone(value);
}
}