From 4edd545b49bb6dd156290c3d11c52f4b980eaa4a Mon Sep 17 00:00:00 2001 From: Josh Sideris Date: Fri, 10 Jun 2016 12:40:36 -0400 Subject: [PATCH] Added a do function. Infinite loop that can be used to run main game updates, etc. --- README.md | 2 +- Sequencr.dev.js | 11 ++++++++++- Sequencr.js | 4 ++-- changelog.md | 3 +++ 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8ce601e..b50b81b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Sequencr.js V2 +# Sequencr.js V3 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 04c2111..e43afed 100644 --- a/Sequencr.dev.js +++ b/Sequencr.dev.js @@ -1,5 +1,5 @@ /* -Sequencr.js V2 +Sequencr.js V3 The MIT License (MIT) Copyright (c) 2016 Joshua Sideris | josh.sideris@gmail.com | https://github.com/JSideris/Sequencr.js @@ -35,6 +35,15 @@ function Sequencr() { onCompleted.call(this); } } + + this.do = function (callback, timeout) { + setTimeout(function (This) { + var ret = callback.call(This); + if(ret !== false){ + Sequencr.do.apply(This, [callback, timeout]); + } + }, timeout, this); + } } var Sequencr = new Sequencr(); diff --git a/Sequencr.js b/Sequencr.js index d770daf..c90fe5d 100644 --- a/Sequencr.js +++ b/Sequencr.js @@ -1,5 +1,5 @@ /* -Sequencr.js V2 +Sequencr.js V3 The MIT License (MIT) Copyright (c) 2016 Joshua Sideris | josh.sideris@gmail.com | https://github.com/JSideris/Sequencr.js @@ -12,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,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 +function Sequencr(){this.chain=function(n,t){Sequencr["for"].apply(this,[0,n.length,function(t){n[t].call(this)},t])},this["for"]=function(n,t,c,i,e){t>n?setTimeout(function(u){var l=c.call(u,n);l!==!1?Sequencr["for"].apply(u,[n+1,t,c,i,e]):e&&e.call(this)},i,this):e&&e.call(this)},this["do"]=function(n,t){setTimeout(function(c){var i=n.call(c);i!==!1&&Sequencr["do"].apply(c,[n,t])},t,this)}}var Sequencr=new Sequencr; \ No newline at end of file diff --git a/changelog.md b/changelog.md index 2e7d882..fc3a9d0 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,6 @@ #Changes +V3 - 2016-06-10 +Added Sequencr.do, which is an infinite version of Sequencr.for that can also be exited by returning false in the callback. Use it for your game's animation loop or whatever. + 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