Skip to content

Commit

Permalink
deprecated .get() in favor of .value
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Sep 4, 2010
1 parent f018025 commit a8d1645
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
13 changes: 8 additions & 5 deletions lib/traverse.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,17 @@ function Traverse (refObj) {
return ref;
}
}
var obj = clone(refObj);
this.value = clone(refObj);

this.get = function () { return obj };
// get() is deprecated, use .value
this.get = function () { return this.value };

this.map = function (f) {
var self = this;

var path = [];
var parents = [];
walk(obj);
walk(this.value);
return this;

function walk (node) {
Expand All @@ -54,10 +57,10 @@ function Traverse (refObj) {
path : [].concat(path),
parent : parents.slice(-1)[0],
key : path.slice(-1)[0],
isRoot : node == obj,
isRoot : node == self.value,
update : function (x) {
if (state.isRoot) {
obj = x;
self.value = x;
}
else {
state.parent.node[state.key] = x;
Expand Down
2 changes: 1 addition & 1 deletion test/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exports['json test'] = function (assert) {
this.update('[Function]');
id++;
}
}).get();
}).value;

assert.equal(
scrubbed.moo, '[Function]',
Expand Down
2 changes: 1 addition & 1 deletion test/negative.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ exports['negative update test'] = function (assert) {
var obj = [ 5, 6, -3, [ 7, 8, -2, 1 ], { f : 10, g : -13 } ];
var fixed = Traverse(obj).map(function (x) {
if (x < 0) this.update(x + 128);
}).get();
}).value;

assert.equal(
sys.inspect(fixed),
Expand Down

0 comments on commit a8d1645

Please sign in to comment.