mirror of
https://github.com/flynx/features.js.git
synced 2025-12-25 04:21:58 +00:00
cleanup + tweaking docs...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
a37e9f8cb0
commit
8a44d91c83
12
README.md
12
README.md
@ -1,8 +1,8 @@
|
||||
# Features
|
||||
|
||||
Features is a module that helps build _features_ out of sets of actions
|
||||
apply them to objects and manage sets of features via external criteria
|
||||
and feature-to-feature dependencies.
|
||||
`features.js` organizes sets of [actions](https://github.com/flynx/actions.js)
|
||||
or _objects_ into features, apply them to objects, manage sets of features via
|
||||
inter-feature dependencies and external criteria.
|
||||
|
||||
|
||||
### The main entities:
|
||||
@ -73,15 +73,15 @@ feature_set.Feature({
|
||||
// alternative configuration location...
|
||||
config: {
|
||||
// ...
|
||||
}
|
||||
},
|
||||
// ...
|
||||
})
|
||||
}),
|
||||
|
||||
// action handlers (optional)
|
||||
handlers: [
|
||||
['action.pre', function(){ /* ... */ }],
|
||||
// ...
|
||||
]
|
||||
],
|
||||
})
|
||||
```
|
||||
|
||||
|
||||
47
features.js
47
features.js
@ -376,10 +376,11 @@ object.Constructor('FeatureSet', {
|
||||
.forEach(function(e){
|
||||
// skip tags not explicitly requested...
|
||||
if(tag != '*' && tag.indexOf(e) < 0){
|
||||
return
|
||||
}
|
||||
exclusive[e] = (exclusive[e] || []).concat([k])
|
||||
rev_exclusive[k] = (rev_exclusive[k] || []).concat([e]) }) })
|
||||
return }
|
||||
exclusive[e] =
|
||||
(exclusive[e] || []).concat([k])
|
||||
rev_exclusive[k] =
|
||||
(rev_exclusive[k] || []).concat([e]) }) })
|
||||
return exclusive },
|
||||
|
||||
// Build list of features in load order...
|
||||
@ -557,8 +558,10 @@ object.Constructor('FeatureSet', {
|
||||
// a feature up in the same chain...
|
||||
// XXX should this break or accumulate???
|
||||
console.warn(`Disable loop detected at "${n}" in chain: ${_seen}`)
|
||||
var loop = _seen.slice(_seen.indexOf(n)).concat([n])
|
||||
data.disable_loops = (data.disable_loops || []).push(loop)
|
||||
var loop =
|
||||
_seen.slice(_seen.indexOf(n)).concat([n])
|
||||
data.disable_loops =
|
||||
(data.disable_loops || []).push(loop)
|
||||
return false }
|
||||
// XXX STUB -- need to resolve actual loops and
|
||||
// make the disable global...
|
||||
@ -610,8 +613,7 @@ object.Constructor('FeatureSet', {
|
||||
// merge lists...
|
||||
;(target instanceof Array ? target : [target])
|
||||
.forEach(function(t){
|
||||
_lst = _lst.concat(feature[t] || [])
|
||||
})
|
||||
_lst = _lst.concat(feature[t] || []) })
|
||||
store[f] = _lst
|
||||
|
||||
// traverse down...
|
||||
@ -711,7 +713,9 @@ object.Constructor('FeatureSet', {
|
||||
// user filter...
|
||||
// NOTE: we build this out of the full feature list...
|
||||
disabled = disabled
|
||||
.concat(isDisabled ? all.filter(isDisabled) : [])
|
||||
.concat(isDisabled ?
|
||||
all.filter(isDisabled)
|
||||
: [])
|
||||
|
||||
// build exclusive groups...
|
||||
// XXX need to sort the values to the same order as given features...
|
||||
@ -733,7 +737,8 @@ object.Constructor('FeatureSet', {
|
||||
// alias...
|
||||
while(f in exclusive && done.indexOf(f) < 0){
|
||||
var candidates = (exclusive[f] || [])
|
||||
.filter(function(c){ return c in features })
|
||||
.filter(function(c){
|
||||
return c in features })
|
||||
|
||||
// resolve alias to non-included feature...
|
||||
if(candidates.length == 0){
|
||||
@ -756,10 +761,11 @@ object.Constructor('FeatureSet', {
|
||||
// replace dependencies...
|
||||
Object.keys(features)
|
||||
.forEach(function(e){
|
||||
var i = features[e] ? features[e].indexOf(f) : -1
|
||||
var i = features[e] ?
|
||||
features[e].indexOf(f)
|
||||
: -1
|
||||
i >= 0
|
||||
&& features[e].splice(i, 1, target)
|
||||
})
|
||||
&& features[e].splice(i, 1, target) })
|
||||
f = target
|
||||
done.push(f) }
|
||||
|
||||
@ -884,9 +890,14 @@ object.Constructor('FeatureSet', {
|
||||
// format:
|
||||
// [ <feature>, <index>, <priority> ]
|
||||
.map(function(e, i){
|
||||
return [e, i, (that[e] && that[e].getPriority) ? that[e].getPriority() : 0 ] })
|
||||
return [e, i,
|
||||
(that[e]
|
||||
&& that[e].getPriority) ?
|
||||
that[e].getPriority()
|
||||
: 0 ] })
|
||||
.sort(function(a, b){
|
||||
return a[2] - b[2] || a[1] - b[1] })
|
||||
return a[2] - b[2]
|
||||
|| a[1] - b[1] })
|
||||
// cleanup...
|
||||
.map(function(e){ return e[0] })
|
||||
// sort by the order features should be loaded...
|
||||
@ -907,8 +918,7 @@ object.Constructor('FeatureSet', {
|
||||
.forEach(function(e){
|
||||
var deps = features[e]
|
||||
if(!deps){
|
||||
return
|
||||
}
|
||||
return }
|
||||
var from = list.indexOf(e)
|
||||
var to = list
|
||||
.map(function(f, i){ return [f, i] })
|
||||
@ -1115,8 +1125,7 @@ object.Constructor('FeatureSet', {
|
||||
deps.length > 0 ?
|
||||
deps.forEach(function(d){
|
||||
graph += `\t"${f}" -> "${d}";\n` })
|
||||
: (graph += `\t"${f}";\n`)
|
||||
})
|
||||
: (graph += `\t"${f}";\n`) })
|
||||
graph += '}'
|
||||
|
||||
return graph },
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user