From b36716c1add7d7ed2ad9af4db7089ef3cbec666e Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 8 Aug 2018 03:55:38 +0300 Subject: [PATCH] fixed a bug in Array.unique(..) (lib/util.js)... Signed-off-by: Alex A. Naanou --- ui (gen4)/features/ui-slideshow.js | 1 + ui (gen4)/lib/util.js | 22 +++++++++++++--------- ui (gen4)/lib/widget/browse.js | 7 +++---- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/ui (gen4)/features/ui-slideshow.js b/ui (gen4)/features/ui-slideshow.js index dae67a37..e2ca38a9 100755 --- a/ui (gen4)/features/ui-slideshow.js +++ b/ui (gen4)/features/ui-slideshow.js @@ -197,6 +197,7 @@ var SlideshowActions = actions.Actions({ length_limit: that.config['slideshow-interval-max-count'], check: Date.str2ms, unique: Date.str2ms, + normalize: function(e){ return e.trim() }, sort: function(a, b){ return Date.str2ms(a) - Date.str2ms(b) }, }) diff --git a/ui (gen4)/lib/util.js b/ui (gen4)/lib/util.js index a91e1006..452dd6dd 100755 --- a/ui (gen4)/lib/util.js +++ b/ui (gen4)/lib/util.js @@ -80,14 +80,16 @@ Array.prototype.toKeys = function(normalize){ // NOTE: normalize will slow things down... Array.prototype.toMap = function(normalize){ return normalize ? - this.reduce(function(m, e, i){ - m.set(normalize(e), i) - return m - }, new Map()) - : this.reduce(function(m, e, i){ - m.set(e, i) - return m - }, new Map()) } + this + .reduce(function(m, e, i){ + m.set(normalize(e), i) + return m + }, new Map()) + : this + .reduce(function(m, e, i){ + m.set(e, i) + return m + }, new Map()) } // Return an array with duplicate elements removed... @@ -97,7 +99,9 @@ Array.prototype.toMap = function(normalize){ // NOTE: for an array containing only strings use a much faster .uniqueStrings(..) // NOTE: this may not work on IE... Array.prototype.unique = function(normalize){ - return new Array(...(new Set(normalize ? this.map(normalize) : this))) } + return normalize ? + [...new Map(this.map(function(e){ return [normalize(e), e] })).values()] + : [...(new Set(this))] } // Compare two arrays... diff --git a/ui (gen4)/lib/widget/browse.js b/ui (gen4)/lib/widget/browse.js index 14038d8e..9e6dbd31 100755 --- a/ui (gen4)/lib/widget/browse.js +++ b/ui (gen4)/lib/widget/browse.js @@ -616,9 +616,8 @@ function(data, options){ // // If a function this will be used to normalize the values before // // uniqueness check is performed... // // -// // NOTE: this (if a function) is different from normalize above -// // in that this will not store the normalized value, rather -// // just use it for uniqueness testing... +// // NOTE: if this is a function the value returned is only used +// // for uniqueness checking and will not be stored. // unique: | function(value){ ... }, // // // called when new item is added to list... @@ -810,7 +809,7 @@ function(list, options){ // account for '$' as key binding marker... lst = lst.unique(function(e){ return e.replace(/\$/g, '') }) - // unique normalized... + // unique filter... } else if(options.unique instanceof Function){ lst = lst.unique(options.unique) }