From eb90a1c3889f235d0766ca8e10bb3a04fb023fff Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sat, 10 Dec 2016 20:01:58 +0300 Subject: [PATCH] added ability to depend on exclusive tags... Signed-off-by: Alex A. Naanou --- features.js | 28 ++++++++++++++++++++++++++-- package.json | 4 ++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/features.js b/features.js index 80ac846..2abd0d9 100755 --- a/features.js +++ b/features.js @@ -42,6 +42,9 @@ var args2array = function(a){ return [].slice.call(a) } // making each sub-feature a strict dependency. // .depends - feature dependencies -- tags of features that must setup // before the feature (list | null) +// NOTE: a feature can depend on an exclusive tag, this will +// remove the need to track which specific exclusive +// tagged feature is loaded... // .exclusive - feature exclusivity tags (list | null) // an exclusivity group enforces that only one feature in // it will be run, i.e. the first / highest priority. @@ -348,6 +351,8 @@ var FeatureSetProto = { var missing = {} var conflicts = {} + var exclusive = {} + // reverse dependency cache... var dependants = {} @@ -394,6 +399,7 @@ var FeatureSetProto = { var deps = that[k].depends || [] var refs = that[k].suggested || [] + var excl = that[k].exclusive || [] deps.forEach(function(n){ // expand lst with dependencies.... @@ -408,6 +414,12 @@ var FeatureSetProto = { refs.forEach(function(n){ lst.indexOf(n) < 0 && lst.push(n) }) + + // build exclusive table... + excl.forEach(function(n){ + var l = exclusive[n] = exclusive[n] || [] + l.indexOf(k) < 0 && l.push(k) + }) } // sort features by priority or position... @@ -435,7 +447,7 @@ var FeatureSetProto = { .filter(function(e){ return disabled.indexOf(e) < 0 }) // build the sort table: [ , , ] .map(function(e, i){ return [ that[e].getPriority(), i, e ] }) - // do the sort... + // sort by priority then index... // NOTE: JS compares lists as strings so we have to compare // the list manually... .sort(function(a, b){ return a[0] - b[0] || a[1] - b[1] }) @@ -539,7 +551,19 @@ var FeatureSetProto = { for(var i=0; i < lst.length; i++){ var k = lst[i] - var depends = that[k].depends || [] + var depends = (that[k].depends || []).slice() + + // replace dependencies that are exclusive tags... + Object.keys(exclusive).forEach(function(e){ + var i = depends.indexOf(e) + i >= 0 + && exclusive[e].forEach(function(f){ + if(lst.indexOf(f) >= 0){ + console.log('EXCL->DEP', e, f) + depends[i] = f + } + }) + }) // list of dependencies to move... var move = [] diff --git a/package.json b/package.json index 2a08a65..3c2ec86 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ig-features", - "version": "2.1.0", + "version": "2.2.0", "description": "", "main": "features.js", "scripts": { @@ -24,6 +24,6 @@ "homepage": "https://github.com/flynx/features.js#readme", "dependencies": { "ig-object": "^1.0.0", - "ig-actions": "^1.0.0" + "ig-actions": "^1.6.0" } }