some refactoring...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2018-12-24 04:39:52 +03:00
parent 88f1d0bc0e
commit e6f1f9e416

View File

@ -304,31 +304,16 @@ var BaseTagsPrototype = {
get length(){ get length(){
return this.values().length }, return this.values().length },
// Definitions as paths...
//
// Each definition is effectively a path in the following form:
// <value>/<tag>
//
// Example:
// .define('tag', 'concept:tag') // -> 'concept:tag/tag'
//
// XXX do we need this???
// XXX should we cache this???
get definition_paths(){
return [...Object.entries(this.definitions)]
.map(function(e){
return [e[1].join(':'), e[0]].join('/') }) },
// All persistent tags... // All persistent tags...
// //
// This will include: // This will include:
// .persistent // .persistent
// .definition_paths // .definitionPaths()
// //
// XXX do we need this??? // XXX do we need this???
get persistentAll(){ get persistentAll(){
return (this.__persistent || new Set()) return (this.__persistent || new Set())
.unite(this.definition_paths || []) }, .unite(this.definitionPaths()) },
// Utils... // Utils...
@ -822,6 +807,42 @@ var BaseTagsPrototype = {
.map(function(s){ return [...s[1]] }) .map(function(s){ return [...s[1]] })
.flat())] }, .flat())] },
// Definitions as paths...
//
// .definitionPaths()
// -> paths
//
// .definitionPaths(tag)
// -> path
// -> undefined
//
// .definitionPaths(tag, ..)
// .definitionPaths([tag, ..])
// -> paths
//
//
// Each definition is effectively a path in the following form:
// <value>/<tag>
//
// Example:
// .define('tag', 'concept:tag') // -> 'concept:tag/tag'
//
definitionPaths: function(...tags){
var definitions = this.definitions || {}
tags = normalizeSplit(tags)
var res = (tags.length == 0 ?
Object.entries(definitions)
: tags
.map(function(tag){
return [tag, definitions[tag]] }))
.map(function(e){
return e[1] != null ?
[e[1].join(':'), e[0]].join('/')
: e[1] })
return arguments.length == 1 && typeof(arguments[0]) == typeof('str') ?
res[0]
:res },
// Edit API... // Edit API...
// //