diff --git a/CHANGELOG.md b/CHANGELOG.md index 644e3ac..4a404ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ ## ChangeLog for: chainjs +## Version 0.0.2 - 2013/12/27 + +- [Feature]: add filter() api +- [Feature]: addstop() api + ## Version 0.0.1 - 2013/12/25 -- Pop step handler use cursor index instead of handlers.shift -- Implemence AOP: before api \ No newline at end of file +- [Normal]: Pop step handler use cursor index instead of handlers.shift +- [Feature]: Implemence AOP: before() api \ No newline at end of file diff --git a/README.md b/README.md index 20a51ae..a9497b0 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,23 @@ Start the chain and invoke start handler Chain(func).then(func1).then(func2).start(); ``` +### start() +Start the chain and invoke start handler +```javascript +Chain(func).then(func1).then(func2).start(); +``` + +### stop() +Stop the chain, mark the chain as ending and destroy local variable +__notice:__after use chain.stop(), the chain contiue execute current step handler, +so use with return for stoping current step excution +```javascript +Chain(func).then(function (chain) { + chain.stop(); + return; +}).start(); +``` + ### next(nextParams) Go to next step ```javascript @@ -83,8 +100,7 @@ var chainData = chain.data(); ``` ### before(beforeHandler) - -Will be invoked before each step +Will be invoked before each step in sync ```javascript Chain(function (chain) {chain.next();}) .then(function (chain) { // Step 1 @@ -98,6 +114,21 @@ Chain(function (chain) {chain.next();}) .start(); ``` +### filter(filterHandler) +Invoked before `before` and `step` handler, it run before each chain step, you should use filter.next() +continue execute next filter or execute current step handler. If use filter.chain in filter, +the chain will skip current step handler and go to next step handler +```javascript +Chain(func, param) + .then(func) + .filter(function (filter) { + console.log('run filter'); + setTimeout( function() { + filter.next(); + }); + }); +``` + ## Testing ```bash diff --git a/build/chain.browser.js b/build/chain.browser.js index 328a091..773a4e8 100644 --- a/build/chain.browser.js +++ b/build/chain.browser.js @@ -278,7 +278,7 @@ if (typeof exports !== 'undefined') { } exports.Chain = Chain; } else { - root.Chain = Chain; + this.Chain = Chain; } }); \ No newline at end of file diff --git a/chain.js b/chain.js index 05e3cad..39f64f8 100644 --- a/chain.js +++ b/chain.js @@ -276,5 +276,5 @@ if (typeof exports !== 'undefined') { } exports.Chain = Chain; } else { - root.Chain = Chain; + this.Chain = Chain; } \ No newline at end of file diff --git a/package.json b/package.json index 8d79274..78415fd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "chainjs", - "version": "0.0.1", + "version": "0.0.2", "description": "Use chaining call to resolve the problem of javascript async callback handle ", "main": "chain.js", "scripts": {