Skip to content

Commit

Permalink
deprecate modify in favor of map
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Sep 4, 2010
1 parent cc59d56 commit f018025
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
8 changes: 5 additions & 3 deletions lib/traverse.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function Traverse (refObj) {

this.get = function () { return obj };

this.modify = function (f) {
this.map = function (f) {
var path = [];
var parents = [];
walk(obj);
Expand Down Expand Up @@ -99,8 +99,10 @@ function Traverse (refObj) {
}
};

this.modify = this.map; // deprecated .modify()

this.forEach = function (f) {
this.modify(function (node) {
this.map(function (node) {
delete this.update;
f.call(this,node);
},null);
Expand Down Expand Up @@ -129,7 +131,7 @@ Traverse.clone = function (obj) {
};

Traverse.map = function (obj, f) {
return Traverse(obj).modify(f).get();
return Traverse(obj).map(f).get();
};

Traverse.forEach = function (obj, f) {
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.1.0",
"version" : "0.1.1",
"description" : "Traverse and transform objects by visiting every node on a recursive walk.",
"author" : "James Halliday",
"license" : "MIT/X11",
Expand Down
2 changes: 1 addition & 1 deletion test/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ exports['json test'] = function (assert) {
var callbacks = {};
var obj = { moo : function () {}, foo : [2,3,4, function () {}] };

var scrubbed = Traverse(obj).modify(function (x) {
var scrubbed = Traverse(obj).map(function (x) {
if (x instanceof Function) {
callbacks[id] = { id : id, f : x, path : this.path };
this.update('[Function]');
Expand Down
2 changes: 1 addition & 1 deletion test/negative.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var sys = require('sys');

exports['negative update test'] = function (assert) {
var obj = [ 5, 6, -3, [ 7, 8, -2, 1 ], { f : 10, g : -13 } ];
var fixed = Traverse(obj).modify(function (x) {
var fixed = Traverse(obj).map(function (x) {
if (x < 0) this.update(x + 128);
}).get();

Expand Down

0 comments on commit f018025

Please sign in to comment.