From e6f1f9e416bd588ef507935c3103b0a00a4b86f4 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Mon, 24 Dec 2018 04:39:52 +0300 Subject: [PATCH] some refactoring... Signed-off-by: Alex A. Naanou --- ui (gen4)/imagegrid/tags.js | 55 +++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/ui (gen4)/imagegrid/tags.js b/ui (gen4)/imagegrid/tags.js index 6cbe06fc..9165c926 100755 --- a/ui (gen4)/imagegrid/tags.js +++ b/ui (gen4)/imagegrid/tags.js @@ -304,31 +304,16 @@ var BaseTagsPrototype = { get length(){ return this.values().length }, - // Definitions as paths... - // - // Each definition is effectively a path in the following form: - // / - // - // 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... // // This will include: // .persistent - // .definition_paths + // .definitionPaths() // // XXX do we need this??? get persistentAll(){ return (this.__persistent || new Set()) - .unite(this.definition_paths || []) }, + .unite(this.definitionPaths()) }, // Utils... @@ -822,6 +807,42 @@ var BaseTagsPrototype = { .map(function(s){ return [...s[1]] }) .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: + // / + // + // 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... //