minor refactoring and cleanup...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2018-12-13 22:31:54 +03:00
parent 3d5f428ce8
commit e0bdcfd33a

View File

@ -441,6 +441,7 @@ var TagsPrototype = {
return that.directMatch(tag, cmp) return that.directMatch(tag, cmp)
.filter(function(t){ .filter(function(t){
return /[\\\/]/.test(t) }) } return /[\\\/]/.test(t) }) }
// search the path tree... // search the path tree...
// NOTE: this will stop the search on first hit... // NOTE: this will stop the search on first hit...
var search = function(tag, seen){ var search = function(tag, seen){
@ -514,7 +515,6 @@ var TagsPrototype = {
// (i.e. ['a:b:c', 'a:b', 'a:c', 'a']) and will only return // (i.e. ['a:b:c', 'a:b', 'a:c', 'a']) and will only return
// the actual full match and an individual tag match... // the actual full match and an individual tag match...
// XXX should it??? // XXX should it???
// XXX should this search up the path???
search: function(query, tags){ search: function(query, tags){
var that = this var that = this
tags = tags == null ? tags = tags == null ?
@ -984,28 +984,29 @@ var TagsPrototype = {
return this return this
}, },
// NOTE: this is a short hand to .rename(tag, '', ..) for extra // NOTE: this is a short hand to .rename(tag, '', ..) for extra
// docs see that... // docs see that...
removeTag: function(tag, ...tags){ removeTag: function(tag, ...tags){
return this.rename(tag, '', ...tags) }, return this.rename(tag, '', ...tags) },
// Remove the given values...
// Tag set/list API...
// //
// XXX should this be join or add??? // .remove(value, ..)
join: function(...others){ // .remove([value, ..])
var that = this // -> this
var index = this.__index || {} //
others remove: function(...values){
.forEach(function(other){ values = (values.length == 1 && values[0] instanceof Array) ?
Object.entries(other.__index || {}) values.pop()
.forEach(function(e){ : values
index[e[0]] = new Set([...(index[e[0]] || []), ...e[1]]) }) }) var res = this.clone()
Object.keys(index).length > 0
&& this.__index == null Object.entries(res.__index || {})
&& (this.__index = index) .forEach(function(e){
return this res.__index[e[0]] = e[1].subtract(values) })
return res
}, },
// Keep only the given values... // Keep only the given values...
@ -1027,26 +1028,25 @@ var TagsPrototype = {
return res return res
}, },
// Remove the given values... // Join 1 or more Tags objects...
// //
// .remove(value, ..) // XXX should this be join or add???
// .remove([value, ..]) join: function(...others){
// -> this var that = this
// var index = this.__index || {}
remove: function(...values){ others
values = (values.length == 1 && values[0] instanceof Array) ? .forEach(function(other){
values.pop() Object.entries(other.__index || {})
: values .forEach(function(e){
var res = this.clone() index[e[0]] = new Set([...(index[e[0]] || []), ...e[1]]) }) })
Object.keys(index).length > 0
Object.entries(res.__index || {}) && this.__index == null
.forEach(function(e){ && (this.__index = index)
res.__index[e[0]] = e[1].subtract(values) }) return this
return res
}, },
// Query API... // Query API...
// //
// //