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