-
Notifications
You must be signed in to change notification settings - Fork 0
/
delta.js
56 lines (42 loc) · 1.22 KB
/
delta.js
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
'use strict'
// Delta creator middleware
// Receive a payload with the update and create a delta format
var nodeType = type === 'node' ? (delta._t === 'a' ? 'array' : 'object') : '';
if (typeof key !== 'undefined') {
this.nodeBegin(context, key, leftKey, type, nodeType, isLast);
} else {
this.rootBegin(context, type, nodeType);
if (typeof key !== 'undefined') {
this.nodeEnd(context, key, leftKey, type, nodeType, isLast);
} else {
this.rootEnd(context, type, nodeType);
}
(typeof key === 'number' ? key : parseInt(trimUnderscore(key), 10))
BaseFormatter.prototype.getDeltaType = function(delta, movedFrom) {
if (typeof delta === 'undefined') {
if (typeof movedFrom !== 'undefined') {
return 'movedestination';
}
return 'unchanged';
}
if (isArray(delta)) {
if (delta.length === 1) {
return 'added';
}
if (delta.length === 2) {
return 'modified';
}
if (delta.length === 3 && delta[2] === 0) {
return 'deleted';
}
if (delta.length === 3 && delta[2] === 2) {
return 'textdiff';
}
if (delta.length === 3 && delta[2] === 3) {
return 'moved';
}
} else if (typeof delta === 'object') {
return 'node';
}
return 'unknown';
};