From 1e47a62c2af392f30a492da732b33b89f23a2e4c Mon Sep 17 00:00:00 2001 From: Tobias Beer Date: Wed, 26 Nov 2014 17:51:27 +0100 Subject: [PATCH 1/3] allows to break out of $tw.utils.each Will improve performance with `$tw.utils.each` callbacks breaking out of the iteration via `return false;`. --- boot/boot.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/boot/boot.js b/boot/boot.js index 4459351a3..a13860552 100644 --- a/boot/boot.js +++ b/boot/boot.js @@ -62,14 +62,19 @@ $tw.utils.isDate = function(value) { Iterate through all the own properties of an object or array. Callback is invoked with (element,title,object) */ $tw.utils.each = function(object,callback) { - var f; + var next, f; + if(object) { if(Object.prototype.toString.call(object) == "[object Array]") { - object.forEach(callback); + for (f = 0; f < object.length; f++) { + next = callback(object[f],f); + if (next === false) break; + } } else { for(f in object) { if(Object.prototype.hasOwnProperty.call(object,f)) { - callback(object[f],f,object); + next = callback(object[f],f,object); + if (next === false) break; } } } @@ -1958,4 +1963,4 @@ if(typeof(exports) !== "undefined") { exports.TiddlyWiki = _boot; } else { _boot(window.$tw); -} +} \ No newline at end of file From 0f157cff908506b50c345c6995d432204d27ccd9 Mon Sep 17 00:00:00 2001 From: Tobias Beer Date: Wed, 26 Nov 2014 18:50:12 +0100 Subject: [PATCH 2/3] code style revision thanks, Jeremy... will watch out for that --- boot/boot.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/boot/boot.js b/boot/boot.js index a13860552..b79c4783b 100644 --- a/boot/boot.js +++ b/boot/boot.js @@ -62,19 +62,23 @@ $tw.utils.isDate = function(value) { Iterate through all the own properties of an object or array. Callback is invoked with (element,title,object) */ $tw.utils.each = function(object,callback) { - var next, f; + var next,f; if(object) { if(Object.prototype.toString.call(object) == "[object Array]") { - for (f = 0; f < object.length; f++) { + for (f=0; f Date: Tue, 2 Dec 2014 12:47:19 +0100 Subject: [PATCH 3/3] added object as third parameter to callback --- boot/boot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boot/boot.js b/boot/boot.js index b79c4783b..8fcc08899 100644 --- a/boot/boot.js +++ b/boot/boot.js @@ -67,7 +67,7 @@ $tw.utils.each = function(object,callback) { if(object) { if(Object.prototype.toString.call(object) == "[object Array]") { for (f=0; f