Skip to content

Commit

Permalink
Only set state.keys when necessary
Browse files Browse the repository at this point in the history
state.keys is set when (a) a non-primitive value is initially traversed,
(b) a primitive value is replaced with an object or vice-versa.
  • Loading branch information
grncdr committed Jun 18, 2012
1 parent 3857dca commit ee66cd1
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ function walk (root, cb, immutable) {

function updateState() {
if (typeof state.node === 'object' && state.node !== null) {
state.keys = Object_keys(state.node);
if (!state.keys || state.node_ !== state.node) {
state.keys = Object_keys(state.node)
}

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

Expand All @@ -175,6 +177,7 @@ function walk (root, cb, immutable) {
}
else {
state.isLeaf = true;
state.keys = null;
}

state.notLeaf = !state.isLeaf;
Expand Down

0 comments on commit ee66cd1

Please sign in to comment.