Skip to content

Commit

Permalink
bump to 0.4.2 for this.block() with a passing test
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Jun 11, 2011
1 parent 18f3e27 commit d945818
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ function walk (root, cb, immutable) {
after : function (f) { modifiers.after = f },
pre : function (f) { modifiers.pre = f },
post : function (f) { modifiers.post = f },
stop : function () { alive = false }
stop : function () { alive = false },
block : function () { keepGoing = false },
};

if (!alive) return state;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name" : "traverse",
"version" : "0.4.1",
"version" : "0.4.2",
"description" : "Traverse and transform objects by visiting every node on a recursive walk",
"author" : "James Halliday",
"license" : "MIT/X11",
Expand Down
16 changes: 16 additions & 0 deletions test/subexpr.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,19 @@ exports.subexpr = function () {
'c', [ 5.9, 6, 6.1 ],
]);
};

exports.block = function () {
var obj = [ [ 1 ], [ 2 ], [ 3 ] ];
var r = traverse(obj).map(function (x) {
if (Array.isArray(x) && !this.isRoot) {
if (x[0] === 5) this.block()
else this.update([ [ x[0] + 1 ] ])
}
});

assert.deepEqual(r, [
[ [ [ [ [ 5 ] ] ] ] ],
[ [ [ [ 5 ] ] ] ],
[ [ [ 5 ] ] ],
]);
};

0 comments on commit d945818

Please sign in to comment.