From d0a24bd9f093e52afe6159f042d758c537943665 Mon Sep 17 00:00:00 2001 From: Tobias Beer Date: Tue, 27 Jan 2015 19:31:23 +0100 Subject: [PATCH] added $tw.utils.pushOnce retained check for basic each nonetheless tests pass --- boot/boot.js | 9 +++++++++ core/modules/filters/each.js | 20 +++++++++----------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/boot/boot.js b/boot/boot.js index acdfa0327..68eb80799 100644 --- a/boot/boot.js +++ b/boot/boot.js @@ -84,6 +84,15 @@ $tw.utils.each = function(object,callback) { } }; +/* +Pushes a value to an array only when not yet contained. +*/ +$tw.utils.pushOnce = function(array,value) { + if(0 > array.indexOf(value)){ + array.push(value); + } +} + /* Helper for making DOM elements tag: tag name diff --git a/core/modules/filters/each.js b/core/modules/filters/each.js index a046923ad..8307ee31b 100644 --- a/core/modules/filters/each.js +++ b/core/modules/filters/each.js @@ -17,19 +17,17 @@ With suffix "list", selects all tiddlers that are values in a specified list fie Export our filter function */ exports.each = function(source,operator,options) { - var results = [], - values = {}, - field = operator.operand || "title", - add = function(val,title) { - if(!$tw.utils.hop(values,val)) { - values[val] = true; - results.push(title); - } - }; + var results =[] , + value,values = {}, + field = operator.operand || "title"; if("list" !== operator.suffix) { source(function(tiddler,title) { if(tiddler) { - add("title" === field ? title : tiddler.getFieldString(field),title); + value = "title" === field ? title : tiddler.getFieldString(field); + if(!$tw.utils.hop(values,value)) { + values[value] = true; + results.push(title); + } } }); } else { @@ -38,7 +36,7 @@ exports.each = function(source,operator,options) { $tw.utils.each( options.wiki.getTiddlerList(title,field), function(value) { - add(value,value); + $tw.utils.pushOnce(results,value); } ); }