Skip to content

Commit 772b2c8

Browse files
committed
Converting path to List type (fixes intelie#3)
1 parent 61bae3b commit 772b2c8

File tree

2 files changed

+15
-51
lines changed

2 files changed

+15
-51
lines changed

src/diff.js

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,42 @@
33
var Immutable = require('immutable');
44
var utils = require('./utils');
55
var lcs = require('./lcs');
6-
var path = require('./path');
7-
var concatPath = path.concat,
8-
escape = path.escape,
9-
op = utils.op,
10-
isMap = utils.isMap,
11-
isIndexed = utils.isIndexed;
6+
var op = utils.op,
7+
isMap = utils.isMap,
8+
isIndexed = utils.isIndexed;
129

1310
var mapDiff = function(a, b, p){
1411
var ops = [];
15-
var path = p || '';
12+
var path = p || [];
1613

1714
if(Immutable.is(a, b) || (a == b == null)){ return ops; }
1815

1916
if(a.forEach){
2017
a.forEach(function(aValue, aKey){
2118
if(b.has(aKey)){
2219
if(isMap(aValue) && isMap(b.get(aKey))){
23-
ops = ops.concat(mapDiff(aValue, b.get(aKey), concatPath(path, escape(aKey))));
20+
ops = ops.concat(mapDiff(aValue, b.get(aKey), path.concat(aKey)));
2421
}
2522
else if(isIndexed(b.get(aKey)) && isIndexed(aValue)){
26-
ops = ops.concat(sequenceDiff(aValue, b.get(aKey), concatPath(path, escape(aKey))));
23+
ops = ops.concat(sequenceDiff(aValue, b.get(aKey), path.concat(aKey)));
2724
}
2825
else {
2926
var bValue = b.get ? b.get(aKey) : b;
3027
var areDifferentValues = (aValue !== bValue);
3128
if (areDifferentValues) {
32-
ops.push(op('replace', concatPath(path, escape(aKey)), bValue));
29+
ops.push(op('replace', path.concat(aKey), bValue));
3330
}
3431
}
3532
}
3633
else {
37-
ops.push( op('remove', concatPath(path, escape(aKey))) );
34+
ops.push( op('remove', path.concat(aKey)) );
3835
}
3936
});
4037
}
4138

4239
b.forEach(function(bValue, bKey){
4340
if(a.has && !a.has(bKey)){
44-
ops.push( op('add', concatPath(path, escape(bKey)), bValue) );
41+
ops.push( op('add', path.concat(bKey), bValue) );
4542
}
4643
});
4744

@@ -62,19 +59,19 @@ var sequenceDiff = function (a, b, p) {
6259
if(diff.op === '='){ pathIndex++; }
6360
else if(diff.op === '!='){
6461
if(isMap(diff.val) && isMap(diff.newVal)){
65-
var mapDiffs = mapDiff(diff.val, diff.newVal, concatPath(path, pathIndex));
62+
var mapDiffs = mapDiff(diff.val, diff.newVal, path.concat(pathIndex));
6663
ops = ops.concat(mapDiffs);
6764
}
6865
else{
69-
ops.push(op('replace', concatPath(path, pathIndex), diff.newVal));
66+
ops.push(op('replace', path.concat(pathIndex), diff.newVal));
7067
}
7168
pathIndex++;
7269
}
7370
else if(diff.op === '+'){
74-
ops.push(op('add', concatPath(path, pathIndex), diff.val));
71+
ops.push(op('add', path.concat(pathIndex), diff.val));
7572
pathIndex++;
7673
}
77-
else if(diff.op === '-'){ ops.push(op('remove', concatPath(path, pathIndex))); }
74+
else if(diff.op === '-'){ ops.push(op('remove', path.concat(pathIndex))); }
7875
});
7976

8077
return ops;
@@ -84,7 +81,7 @@ var primitiveTypeDiff = function (a, b, p) {
8481
var path = p || '';
8582
if(a === b){ return []; }
8683
else{
87-
return [ op('replace', concatPath(path, ''), b) ];
84+
return [ op('replace', path.concat(''), b) ];
8885
}
8986
};
9087

@@ -101,4 +98,4 @@ var diff = function(a, b, p){
10198
}
10299
};
103100

104-
module.exports = diff;
101+
module.exports = diff;

src/path.js

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)