Comparing version 0.2.1 to 0.2.2
@@ -28,19 +28,32 @@ (function() { | ||
setupAction = function(actionName, obj, arg) { | ||
var Promise, action, call, catcher, def, hookIn, names; | ||
catcher = arg["catch"], names = arg.names, def = arg["default"], Promise = arg.Promise; | ||
var Promise, action, args, call, catcher, def, hookIn, names; | ||
catcher = arg["catch"], names = arg.names, def = arg["default"], Promise = arg.Promise, args = arg.args; | ||
if ((catcher != null) && !isFunction(catcher)) { | ||
catcher = catcher[actionName]; | ||
} | ||
if (args != null) { | ||
if (!isArray(args)) { | ||
args = [obj, args]; | ||
} else { | ||
args.unshift(obj); | ||
} | ||
} else { | ||
args = [obj]; | ||
} | ||
call = function(o) { | ||
var promise; | ||
var _args, promise; | ||
if (o == null) { | ||
o = obj; | ||
} | ||
_args = args.slice(); | ||
_args.unshift(o); | ||
promise = (action._chain.reduce((function(lastPromise, hooks) { | ||
if (hooks.length === 1) { | ||
return lastPromise.then(hooks[0].bind(obj, o, obj)); | ||
return lastPromise.then(function() { | ||
return hooks[0].apply(obj, _args); | ||
}); | ||
} else { | ||
return lastPromise.then(function() { | ||
return Promise.all(hooks.map(function(hook) { | ||
return hook.call(obj, o, obj); | ||
return hook.apply(obj, _args); | ||
})); | ||
@@ -47,0 +60,0 @@ }); |
{ | ||
"name": "hook-up", | ||
"description": "Create your own hook api with 2-dimensional hooks - better than events or simple hooks", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"homepage": "https://github.com/paulpflug/", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -72,3 +72,4 @@ # hook-up | ||
"cache.get": (e) => { console.error(e) } | ||
} | ||
}, | ||
args: [someArg] | ||
}) | ||
@@ -79,4 +80,5 @@ | ||
// (see below) | ||
program.run.hookIn((state,{config}) => { | ||
program.run.hookIn((state,{config},someArg) => { | ||
// config equals program.config | ||
// someArg is passed from above | ||
// it is recommend to test the state if you depend on it | ||
@@ -115,2 +117,3 @@ // as you have no idea what the previous cbs did | ||
Promise | Object | native Promise | Promise lib to use | ||
args | Object or Array of Objects | - | additonal args passed on each action call | ||
names | Object | - | see below | ||
@@ -117,0 +120,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11298
192
141