From da5048b971201bfdc0e43f10501ee32b2bcea702 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Tue, 3 Apr 2018 02:24:07 +0300 Subject: [PATCH] more speedup and refactoring... Signed-off-by: Alex A. Naanou --- ui (gen4)/features/marks.js | 32 ++++++++++++++------------------ ui (gen4)/imagegrid/data.js | 27 +++++++++++++++------------ 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/ui (gen4)/features/marks.js b/ui (gen4)/features/marks.js index eee4ceaa..fe058e32 100755 --- a/ui (gen4)/features/marks.js +++ b/ui (gen4)/features/marks.js @@ -479,16 +479,14 @@ module.ImageMarksUI = core.ImageGridFeatures.Feature({ // XXX is this the right way to go??? ['updateImage', function(_, gid, img){ - // update only when ribbons are preset... - if(this.ribbons != null){ - // NOTE: we are not using .toggleMark(..) here as this - // does not need to depend on the 'edit' feature... - if(this.data.toggleTag('selected', gid, '?') == 'on'){ - this.ribbons.toggleImageMark(gid, 'selected', 'on') - } else { - this.ribbons.toggleImageMark(gid, 'selected', 'off') - } - } + // NOTE: we are not using .toggleMark(..) here as this + // does not need to depend on the 'edit' feature... + this.ribbons + && this.ribbons + .toggleImageMark( + gid, + 'selected', + this.data.hasTag(gid, 'selected') ? 'on' : 'off') }], ], }) @@ -604,14 +602,12 @@ module.ImageBookmarksUI = core.ImageGridFeatures.Feature({ handlers: [ // XXX is this the right way to go??? ['updateImage', function(_, gid, img){ - // update only when ribbons are preset... - if(this.ribbons != null){ - if(this.data.toggleTag('bookmark', gid, '?') == 'on'){ - this.ribbons.toggleImageMark(gid, 'bookmark', 'on') - } else { - this.ribbons.toggleImageMark(gid, 'bookmark', 'off') - } - } + this.ribbons + && this.ribbons + .toggleImageMark( + gid, + 'bookmark', + this.data.hasTag(gid, 'bookmark') ? 'on' : 'off') }], ], }) diff --git a/ui (gen4)/imagegrid/data.js b/ui (gen4)/imagegrid/data.js index f02a34d6..fb75406f 100755 --- a/ui (gen4)/imagegrid/data.js +++ b/ui (gen4)/imagegrid/data.js @@ -379,11 +379,13 @@ var DataPrototype = { // NOTE: this is slow-ish... removeDuplicates: function(lst, skip_undefined){ skip_undefined = skip_undefined == null ? true : skip_undefined + var lst_idx = lst.toKeys() for(var i=0; i < lst.length; i++){ if(skip_undefined && lst[i] == null){ continue } - if(lst.indexOf(lst[i]) != i){ + //if(lst.indexOf(lst[i]) != i){ + if(lst_idx[lst[i]] != i){ lst.splice(i, 1) i -= 1 } @@ -3126,27 +3128,26 @@ var DataWithTagsPrototype = { return gids.length > 1 ? gids.map(function(gid){ return 'off' }) : 'off' } var that = this - var tagset = this.tags + var tagset = this.tags || {} var order = this.order - var res = gids.map(function(gid){ - gid = that.getImage(gid) - if(!(tag in tagset)){ - return 'off' - } - //return that.getTags(gid).indexOf(tag) != -1 ? 'on' : 'off' - return tagset[tag][order.indexOf(gid)] != null ? 'on' : 'off' - }) + var order_idx = order.toKeys() + var res = tag in tagset ? + gids.map(function(gid){ + gid = that.getImage(gid) + return tagset[tag][order_idx[gid]] != null ? 'on' : 'off' + }) + : gids.map(function(){ return 'off' }) // toggle each... } else { var that = this var tagset = this.tags var order = this.order + var order_idx = order.toKeys() var res = gids.map(function(gid){ gid = that.getImage(gid) - //var t = that.getTags(gid).indexOf(tag) != -1 ? 'off' : 'on' var t = tagset == null || !(tag in tagset) ? 'on' - : tagset[tag][order.indexOf(gid)] == null ? 'on' + : tagset[tag][order_idx[gid]] == null ? 'on' : 'off' if(t == 'on'){ that.tag(tag, gid) @@ -3160,6 +3161,8 @@ var DataWithTagsPrototype = { return res.length == 1 ? res[0] : res }, + hasTag: function(gid, tag){ + return ((this.tags || {})[tag] || []).indexOf(this.getImage(gid)) >= 0 }, getTags: function(gids){ gids = arguments.length > 1 ? [].slice.call(arguments) : gids == null || gids == 'current' ? this.getImage()