diff --git a/README.md b/README.md index ac8f76e..8ce601e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Sequencr.js +# Sequencr.js V2 Sequencr.js is a super-light-weight library that allows you to easily chain function calls together with timeouts in between, or set timeouts between iterations of a loop. Please read the wiki for more information, and usage. diff --git a/Sequencr.dev.js b/Sequencr.dev.js index 2c5d433..04c2111 100644 --- a/Sequencr.dev.js +++ b/Sequencr.dev.js @@ -1,4 +1,6 @@ /* +Sequencr.js V2 + The MIT License (MIT) Copyright (c) 2016 Joshua Sideris | josh.sideris@gmail.com | https://github.com/JSideris/Sequencr.js @@ -20,8 +22,13 @@ function Sequencr() { this.for = function (startInclusive, endExclusive, callback, timeout, onCompleted) { if (startInclusive < endExclusive) { setTimeout(function (This) { - callback.call(This, startInclusive); - Sequencr.for.apply(This, [startInclusive + 1, endExclusive, callback, timeout, onCompleted]); + var ret = callback.call(This, startInclusive); + if(ret !== false){ + Sequencr.for.apply(This, [startInclusive + 1, endExclusive, callback, timeout, onCompleted]); + } + else if(onCompleted) { + onCompleted.call(this); + } }, timeout, this); } else if(onCompleted) { diff --git a/Sequencr.js b/Sequencr.js index a776c6a..d770daf 100644 --- a/Sequencr.js +++ b/Sequencr.js @@ -1,4 +1,6 @@ /* +Sequencr.js V2 + The MIT License (MIT) Copyright (c) 2016 Joshua Sideris | josh.sideris@gmail.com | https://github.com/JSideris/Sequencr.js @@ -10,4 +12,4 @@ and to permit persons to whom the Software is furnished to do so, subject to the The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. */ -function Sequencr(){this.chain=function(n,c){Sequencr["for"].apply(this,[0,n.length,function(c){n[c].call(this)},c])},this["for"]=function(n,c,e,t,i){c>n?setTimeout(function(u){e.call(u,n),Sequencr["for"].apply(u,[n+1,c,e,t,i])},t,this):i&&i.call(this)}}var Sequencr=new Sequencr; +function Sequencr(){this.chain=function(n,c){Sequencr["for"].apply(this,[0,n.length,function(c){n[c].call(this)},c])},this["for"]=function(n,c,t,e,i){c>n?setTimeout(function(l){var u=t.call(l,n);u!==!1?Sequencr["for"].apply(l,[n+1,c,t,e,i]):i&&i.call(this)},e,this):i&&i.call(this)}}var Sequencr=new Sequencr; \ No newline at end of file diff --git a/changelog.md b/changelog.md new file mode 100644 index 0000000..2e7d882 --- /dev/null +++ b/changelog.md @@ -0,0 +1,3 @@ +#Changes +V2 - 2016-06-09 +Added ability to break out of a for loop by returning false. This will immediately invoke the onCompleted callback. \ No newline at end of file