Skip to content

Commit

Permalink
Added documentation for stopHere-flag on remove and delete
Browse files Browse the repository at this point in the history
  • Loading branch information
karlbohlmark committed Oct 13, 2011
1 parent 4aa61ef commit 2bb8018
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ Set a new value for the present node.
All the elements in `value` will be recursively traversed unless `stopHere` is
true.

this.remove()
this.remove(stopHere=false)
-------------

Remove the current element from the output. If the node is in an Array it will
be spliced off. Otherwise it will be deleted from its parent.

this.delete()
this.delete(stopHere=false)
-------------

Delete the current element from its parent in the output. Calls `delete` even on
Expand Down
12 changes: 6 additions & 6 deletions test/mutability.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,27 +98,27 @@ exports.remove = function () {
};

exports.removeNoStop = function() {
var obj = { a : 1, b : 2, c : { d: 3, e: 4 } };
var obj = { a : 1, b : 2, c : { d: 3, e: 4 }, f: 5 };

var keysWithoutStop = [];
var keys = [];
Traverse(obj).forEach(function (x) {
keysWithoutStop.push(this.key)
keys.push(this.key)
if (this.key == 'c') this.remove();
});

assert.deepEqual(keysWithoutStop, [undefined, 'a', 'b', 'c', 'd', 'e'])
assert.deepEqual(keys, [undefined, 'a', 'b', 'c', 'd', 'e', 'f'])
}

exports.removeStop = function() {
var obj = { a : 1, b : 2, c : { d: 3, e: 4 } };
var obj = { a : 1, b : 2, c : { d: 3, e: 4 }, f: 5 };

var keys = [];
Traverse(obj).forEach(function (x) {
keys.push(this.key)
if (this.key == 'c') this.remove(true);
});

assert.deepEqual(keys, [undefined, 'a', 'b', 'c'])
assert.deepEqual(keys, [undefined, 'a', 'b', 'c', 'f'])
}

exports.removeMap = function () {
Expand Down

0 comments on commit 2bb8018

Please sign in to comment.