From 5963adf92eb88ee8725ba6f381e59acce2d1bea5 Mon Sep 17 00:00:00 2001 From: Skeeve Date: Sat, 17 Feb 2018 19:51:18 +0100 Subject: [PATCH] Bugfix/3117 inconsistent each (#3124) * Following Jeremy's proposal of using a new suffix * typo fixed --- core/modules/filters/each.js | 34 ++++++++++++++----- .../tiddlers/filters/examples/each.tid | 2 ++ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/core/modules/filters/each.js b/core/modules/filters/each.js index 25e852638..5c2c29077 100644 --- a/core/modules/filters/each.js +++ b/core/modules/filters/each.js @@ -18,18 +18,34 @@ Export our filter function */ exports.each = function(source,operator,options) { var results =[] , - value,values = {}, - field = operator.operand || "title"; - if(operator.suffix !== "list-item") { + value,values = {}, + field = operator.operand || "title"; + if(operator.suffix === "value" && field === "title") { source(function(tiddler,title) { - if(tiddler) { - value = (field === "title") ? title : tiddler.getFieldString(field); - if(!$tw.utils.hop(values,value)) { - values[value] = true; - results.push(title); - } + if(!$tw.utils.hop(values,title)) { + values[title] = true; + results.push(title); } }); + } else if(operator.suffix !== "list-item") { + if(field === "title") { + source(function(tiddler,title) { + if(tiddler && !$tw.utils.hop(values,title)) { + values[title] = true; + results.push(title); + } + }); + } else { + source(function(tiddler,title) { + if(tiddler) { + value = tiddler.getFieldString(field); + if(!$tw.utils.hop(values,value)) { + values[value] = true; + results.push(title); + } + } + }); + } } else { source(function(tiddler,title) { if(tiddler) { diff --git a/editions/tw5.com/tiddlers/filters/examples/each.tid b/editions/tw5.com/tiddlers/filters/examples/each.tid index f6e2ed23b..4c6a746ed 100644 --- a/editions/tw5.com/tiddlers/filters/examples/each.tid +++ b/editions/tw5.com/tiddlers/filters/examples/each.tid @@ -7,5 +7,7 @@ type: text/vnd.tiddlywiki <<.operator-example 1 "[each[color]]">> <<.operator-example 2 "[sort[title]each[type]]" "the alphabetically first tiddler of each type">> <<.operator-example 3 "[each:list-item[list]]" "all tiddlers listed anywhere in the core list field">> +<<.operator-example 4 "[[Non existing]] [[GettingStarted]] +[each:value[]]" "Compare this to `+[each[]]` below">> +<<.operator-example 5 "[[Non existing]] [[GettingStarted]] +[each[]]" "Compare this to `+[each:value[]]` above">> For an example of using the <<.op each>> operator to generate a two-tier list of groups and members, see [[GroupedLists]].