From 63cb425c8a59b5057b52a0c788be22fc097783d6 Mon Sep 17 00:00:00 2001 From: Chad Killingsworth Date: Fri, 15 Apr 2016 06:22:45 -0500 Subject: [PATCH] Add a general walk method that has both a pre and post visit callback --- index.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/index.js b/index.js index b31a3ab..2485bf7 100644 --- a/index.js +++ b/index.js @@ -223,6 +223,16 @@ extend(Walker.prototype, { walkImpl(obj, traversalStrategy, visitor, null, context); }, + // Recursively traverses `obj` in a depth-first fashion, invoking the + // `preVisitor` function for each object before traversing its children + // and the `postVisitor` function after traversing its children + // `traversalStrategy` is intended for internal callers, and is not part + // of the public API. + walk: function(obj, preVisitor, postVisitor, context, traversalStrategy) { + traversalStrategy = traversalStrategy || this._traversalStrategy; + walkImpl(obj, traversalStrategy, preVisitor, postVisitor, context); + }, + // Builds up a single value by doing a post-order traversal of `obj` and // calling the `visitor` function on each object in the tree. For leaf // objects, the `memo` argument to `visitor` is the value of the `leafMemo`