more speedup and refactoring...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2018-04-03 02:24:07 +03:00
parent a04ac505c5
commit da5048b971
2 changed files with 29 additions and 30 deletions

View File

@ -479,16 +479,14 @@ module.ImageMarksUI = core.ImageGridFeatures.Feature({
// XXX is this the right way to go??? // XXX is this the right way to go???
['updateImage', function(_, gid, img){ ['updateImage', function(_, gid, img){
// update only when ribbons are preset...
if(this.ribbons != null){
// NOTE: we are not using .toggleMark(..) here as this // NOTE: we are not using .toggleMark(..) here as this
// does not need to depend on the 'edit' feature... // does not need to depend on the 'edit' feature...
if(this.data.toggleTag('selected', gid, '?') == 'on'){ this.ribbons
this.ribbons.toggleImageMark(gid, 'selected', 'on') && this.ribbons
} else { .toggleImageMark(
this.ribbons.toggleImageMark(gid, 'selected', 'off') gid,
} 'selected',
} this.data.hasTag(gid, 'selected') ? 'on' : 'off')
}], }],
], ],
}) })
@ -604,14 +602,12 @@ module.ImageBookmarksUI = core.ImageGridFeatures.Feature({
handlers: [ handlers: [
// XXX is this the right way to go??? // XXX is this the right way to go???
['updateImage', function(_, gid, img){ ['updateImage', function(_, gid, img){
// update only when ribbons are preset... this.ribbons
if(this.ribbons != null){ && this.ribbons
if(this.data.toggleTag('bookmark', gid, '?') == 'on'){ .toggleImageMark(
this.ribbons.toggleImageMark(gid, 'bookmark', 'on') gid,
} else { 'bookmark',
this.ribbons.toggleImageMark(gid, 'bookmark', 'off') this.data.hasTag(gid, 'bookmark') ? 'on' : 'off')
}
}
}], }],
], ],
}) })

View File

@ -379,11 +379,13 @@ var DataPrototype = {
// NOTE: this is slow-ish... // NOTE: this is slow-ish...
removeDuplicates: function(lst, skip_undefined){ removeDuplicates: function(lst, skip_undefined){
skip_undefined = skip_undefined == null ? true : skip_undefined skip_undefined = skip_undefined == null ? true : skip_undefined
var lst_idx = lst.toKeys()
for(var i=0; i < lst.length; i++){ for(var i=0; i < lst.length; i++){
if(skip_undefined && lst[i] == null){ if(skip_undefined && lst[i] == null){
continue continue
} }
if(lst.indexOf(lst[i]) != i){ //if(lst.indexOf(lst[i]) != i){
if(lst_idx[lst[i]] != i){
lst.splice(i, 1) lst.splice(i, 1)
i -= 1 i -= 1
} }
@ -3126,27 +3128,26 @@ var DataWithTagsPrototype = {
return gids.length > 1 ? gids.map(function(gid){ return 'off' }) : 'off' return gids.length > 1 ? gids.map(function(gid){ return 'off' }) : 'off'
} }
var that = this var that = this
var tagset = this.tags var tagset = this.tags || {}
var order = this.order var order = this.order
var res = gids.map(function(gid){ var order_idx = order.toKeys()
var res = tag in tagset ?
gids.map(function(gid){
gid = that.getImage(gid) gid = that.getImage(gid)
if(!(tag in tagset)){ return tagset[tag][order_idx[gid]] != null ? 'on' : 'off'
return 'off'
}
//return that.getTags(gid).indexOf(tag) != -1 ? 'on' : 'off'
return tagset[tag][order.indexOf(gid)] != null ? 'on' : 'off'
}) })
: gids.map(function(){ return 'off' })
// toggle each... // toggle each...
} else { } else {
var that = this var that = this
var tagset = this.tags var tagset = this.tags
var order = this.order var order = this.order
var order_idx = order.toKeys()
var res = gids.map(function(gid){ var res = gids.map(function(gid){
gid = that.getImage(gid) gid = that.getImage(gid)
//var t = that.getTags(gid).indexOf(tag) != -1 ? 'off' : 'on'
var t = tagset == null || !(tag in tagset) ? 'on' var t = tagset == null || !(tag in tagset) ? 'on'
: tagset[tag][order.indexOf(gid)] == null ? 'on' : tagset[tag][order_idx[gid]] == null ? 'on'
: 'off' : 'off'
if(t == 'on'){ if(t == 'on'){
that.tag(tag, gid) that.tag(tag, gid)
@ -3160,6 +3161,8 @@ var DataWithTagsPrototype = {
return res.length == 1 ? res[0] : res return res.length == 1 ? res[0] : res
}, },
hasTag: function(gid, tag){
return ((this.tags || {})[tag] || []).indexOf(this.getImage(gid)) >= 0 },
getTags: function(gids){ getTags: function(gids){
gids = arguments.length > 1 ? [].slice.call(arguments) gids = arguments.length > 1 ? [].slice.call(arguments)
: gids == null || gids == 'current' ? this.getImage() : gids == null || gids == 'current' ? this.getImage()