some exploring....

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2017-10-16 22:22:41 +03:00
parent a9be1b04fb
commit 05a86cf36a

View File

@ -54,17 +54,73 @@ var toggler = require('lib/toggler')
/*********************************************************************/ /*********************************************************************/
// Make a protocol implementation action... // Make a chained action...
//
// // basic chained action...
// basicAction: ['Group/Basic action',
// core.chain('working',
// // action...
// function(){
// ...
// })],
//
// // conditional chained action...
// conditionalAction: ['Group/Conditional action',
// core.chain('working',
// // action predicate...
// function(){
// return ...
// },
// // action...
// function(){
// ...
// })],
//
// //
// For more docs see: docs for actions.js and .chainApply(..) // For more docs see: docs for actions.js and .chainApply(..)
// //
// XXX might be good to move this to actions.js // XXX might be good to move this to actions.js
// XXX might also be a good idea to mark the actual protocol definition // XXX might also be a good idea to mark the actual protocol definition
// and not just the implementation... // and not just the implementation...
var protocol = // XXX is this actually simpler?
module.protocol = function(protocol, func){ // conditionalActionNew: ['Group/Conditional action',
// core.chain('working',
// function(){
// return this.condition == true
// },
// function(){
// ...
// })],
//
// conditionalActionOld: ['Group/Conditional action',
// function(){
// if(this.condition != true){
// return
// }
// this.working.chainApply(this, function(){
// ...
// })
// }],
//
// Advantages:
// - documentable/groupable automatically...
//
// Disadvantages:
// - extra entity/abstraction to remember...
// - covers only one simple case..
var chain =
module.chain = function(action, a, b){
if(arguments.length == 3){
var func = b
var cond = a
} else {
var func = a
var cond = true
}
return function(){ return function(){
return this[protocol].chainApply(this, func, arguments) if(cond === true || cond.apply(this, arguments)){
return this[action].chainApply(this, func, arguments)
}
} }
} }