Skip to content

Commit

Permalink
fixed merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Jun 19, 2012
2 parents ef3694f + 28d5fb6 commit 576832a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 14 deletions.
37 changes: 23 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,24 +160,31 @@ function walk (root, cb, immutable) {

if (!alive) return state;

if (typeof node === 'object' && node !== null) {
state.keys = objectKeys(node);

state.isLeaf = state.keys.length == 0;

for (var i = 0; i < parents.length; i++) {
if (parents[i].node_ === node_) {
state.circular = parents[i];
break;
function updateState() {
if (typeof state.node === 'object' && state.node !== null) {
if (!state.keys || state.node_ !== state.node) {
state.keys = objectKeys(state.node)
}

state.isLeaf = state.keys.length == 0;

for (var i = 0; i < parents.length; i++) {
if (parents[i].node_ === node_) {
state.circular = parents[i];
break;
}
}
}
}
else {
state.isLeaf = true;
else {
state.isLeaf = true;
state.keys = null;
}

state.notLeaf = !state.isLeaf;
state.notRoot = !state.isRoot;
}

state.notLeaf = !state.isLeaf;
state.notRoot = !state.isRoot;
updateState();

// use return values to update if defined
var ret = cb.call(state, state.node);
Expand All @@ -191,6 +198,8 @@ function walk (root, cb, immutable) {
&& state.node !== null && !state.circular) {
parents.push(state);

updateState();

forEach(state.keys, function (key, i) {
path.push(key);

Expand Down
27 changes: 27 additions & 0 deletions test/mutability.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,30 @@ test('deleteMapRedux', function (t) {

t.end();
});

test('objectToString', function (t) {
var obj = { a : 1, b : 2, c : [ 3, 4 ] };
var res = traverse(obj).forEach(function (x) {
if (typeof x === 'object' && !this.isRoot) {
this.update(JSON.stringify(x));
}
});
t.same(obj, res);
t.same(obj, { a : 1, b : 2, c : "[3,4]" });
t.end();
});

test('stringToObject', function (t) {
var obj = { a : 1, b : 2, c : "[3,4]" };
var res = traverse(obj).forEach(function (x) {
if (typeof x === 'string') {
this.update(JSON.parse(x));
}
else if (typeof x === 'number' && x % 2 === 0) {
this.update(x * 10);
}
});
t.deepEqual(obj, res);
t.deepEqual(obj, { a : 1, b : 20, c : [ 3, 40 ] });
t.end();
});

0 comments on commit 576832a

Please sign in to comment.