From a5ea1e9a7c7e534753be58ffe994497e83f87511 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sat, 4 May 2019 14:59:35 +0300 Subject: [PATCH] added exit mode to done(..) Signed-off-by: Alex A. Naanou --- README.md | 4 ++-- package.json | 2 +- walk.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 52b9e5b..0b2b0c8 100644 --- a/README.md +++ b/README.md @@ -170,8 +170,8 @@ Stop walking and return `state`. The passed `state` is directly returned from th #### `done(..)` -`done(state) -> state` -User provided function, if given, is called by the *walker* after walking is done (no more nodes to handle). `state` is passed as argument and the return value is returned from the *walker*. This is run in the same context (`this`) as `getter(..)`. +`done(state, mode) -> state` +User provided function, if given, is called by the *walker* after walking is done (no more nodes to handle). `state` is passed as argument and the return value is returned from the *walker*. If walking was stopped via `stop(..)` mode will be `'stopped'` otherwise it is `'done'`. This is run in the same context (`this`) as `getter(..)`. ## Examples diff --git a/package.json b/package.json index 2c13563..0877e36 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "generic-walk", - "version": "1.3.1", + "version": "1.4.0", "description": "An extensible tree walk(..) framework...", "main": "walk.js", "scripts": { diff --git a/walk.js b/walk.js index e5a0879..51868de 100644 --- a/walk.js +++ b/walk.js @@ -151,7 +151,7 @@ function(getter, state, ...nodes){ // call the done handler... res = done ? - done.call(context, res) + done.call(context, res, WalkStopException ? 'stopped': 'done') : res return res