minor refactoring...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2018-12-12 20:18:41 +03:00
parent 21ce93f7b7
commit 47c5c04956

View File

@ -472,66 +472,6 @@ var TagsPrototype = {
get length(){
return this.values().length },
// Toggle a tag to persistent/non-persistent...
//
// A persistent is not removed when untagging a value.
//
// .togglePersistent(tag)
// .togglePersistent(tag, tag, ...)
// .togglePersistent([tag, tag, ...])
// -> states
//
// .togglePersistent(tag, action)
// .togglePersistent(tag, tag, ..., action)
// .togglePersistent([tag, tag, ...], action)
// -> states
//
//
// action can be:
// 'on' - toggle all tags on
// 'off' - toggle all off
// 'toggle' - toggle all depending on initial state
// '?' - return list of states
//
//
// XXX one way to play with this is to add a special tag to set/path
// to make it persistent...
// Example:
// .tag('abc', ...) -> 'abc' is a normal tag...
//
// .tag('persistent:abc', ...) -> 'abc' is persistent...
// .tag('persistent/abc', ...) -> 'abc' is persistent...
//
// We would need "virtual" tags for this, i.e. tags that are
// not actually added to the index but are used for system
// stuff...
togglePersistent: function(...tags){
action = ['on', 'off', 'toggle', '?'].includes(tags[tags.length-1]) ?
tags.pop()
: 'toggle'
tags = (tags[0] instanceof Array && tags.length == 1) ?
tags.pop()
: tags
var persistent =
this.__persistent_tags =
this.__persistent_tags || new Set()
return this.normalizeTags(tags)
.map(function(tag){
return action == 'on' ?
(persistent.add(tag), 'on')
: action == 'off' ?
(persistent.delete(tag), 'off')
: action == 'toggle' ?
(persistent.has(tag) ?
(persistent.delete(tag), 'off')
: (persistent.add(tag), 'on'))
: (persistent.has(tag) ?
'on'
: 'off') })
},
// XXX can these be faster???
// XXX should these take multiple values???
hasTag: function(tag){
@ -552,6 +492,7 @@ var TagsPrototype = {
},
// Tags present in the system...
//
// Get all tags...
@ -806,6 +747,67 @@ var TagsPrototype = {
(that.tag(tag, v), true)
: null) }) },
// Toggle a tag to persistent/non-persistent...
//
// A persistent is not removed when untagging a value.
//
// .togglePersistent(tag)
// .togglePersistent(tag, tag, ...)
// .togglePersistent([tag, tag, ...])
// -> states
//
// .togglePersistent(tag, action)
// .togglePersistent(tag, tag, ..., action)
// .togglePersistent([tag, tag, ...], action)
// -> states
//
//
// action can be:
// 'on' - toggle all tags on
// 'off' - toggle all off
// 'toggle' - toggle all depending on initial state
// '?' - return list of states
//
//
// XXX one way to play with this is to add a special tag to set/path
// to make it persistent...
// Example:
// .tag('abc', ...) -> 'abc' is a normal tag...
//
// .tag('persistent:abc', ...) -> 'abc' is persistent...
// .tag('persistent/abc', ...) -> 'abc' is persistent...
//
// We would need "virtual" tags for this, i.e. tags that are
// not actually added to the index but are used for system
// stuff...
togglePersistent: function(...tags){
action = ['on', 'off', 'toggle', '?'].includes(tags[tags.length-1]) ?
tags.pop()
: 'toggle'
tags = (tags[0] instanceof Array && tags.length == 1) ?
tags.pop()
: tags
var persistent =
this.__persistent_tags =
this.__persistent_tags || new Set()
return this.normalizeTags(tags)
.map(function(tag){
return action == 'on' ?
(persistent.add(tag), 'on')
: action == 'off' ?
(persistent.delete(tag), 'off')
: action == 'toggle' ?
(persistent.has(tag) ?
(persistent.delete(tag), 'off')
: (persistent.add(tag), 'on'))
: (persistent.has(tag) ?
'on'
: 'off') })
},
// Tag set/list API...
//