mirror of
https://github.com/flynx/actions.js.git
synced 2025-10-29 18:30:10 +00:00
some refactoring -- now Action(..) is almost compatible with how actions are defiden in action set...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
6f19b96a95
commit
f0c6c16c32
@ -363,7 +363,7 @@ _action_ is build-in.
|
||||
All action protocol details apply.
|
||||
|
||||
**Notes:**
|
||||
- there is not reliable way to call the post phase without first
|
||||
- there is no reliable way to call the post phase without first
|
||||
calling the pre phase due to how the pre phase is defined (i.e.
|
||||
pre phase functions can return post phase functions).
|
||||
|
||||
|
||||
39
actions.js
39
actions.js
@ -291,6 +291,12 @@ function(func){
|
||||
|
||||
// Construct an action object...
|
||||
//
|
||||
// Action(<name>, <function>)
|
||||
// Action(<name>[, <doc>[, <long-doc>]][, <attrs>,] <function>)
|
||||
// Action(<name>, [ [<doc>[, <long-doc>]][, <attrs>,] <function> ])
|
||||
// -> <action>
|
||||
//
|
||||
//
|
||||
// Action function format:
|
||||
//
|
||||
// // pre event code...
|
||||
@ -356,13 +362,13 @@ function(func){
|
||||
// XXX might be a good idea to add an option to return the full results...
|
||||
var Action =
|
||||
module.Action =
|
||||
function Action(name, doc, ldoc, func){
|
||||
function Action(name, doc, ldoc, attrs, func){
|
||||
// we got called without a 'new'...
|
||||
if(this == null || this.constructor !== Action){
|
||||
// XXX using something like .apply(.., arguemnts) would be more
|
||||
// generel but have no time to figure out how to pass it
|
||||
// to new without the later complaining...
|
||||
return new Action(name, doc, ldoc, func)
|
||||
return new Action(name, doc, ldoc, attrs, func)
|
||||
}
|
||||
|
||||
// prevent action overloading...
|
||||
@ -375,6 +381,18 @@ function Action(name, doc, ldoc, func){
|
||||
return meth.chainApply(this, null, arguments) }
|
||||
meth.__proto__ = this.__proto__
|
||||
|
||||
// precess args...
|
||||
var args = doc instanceof Array ?
|
||||
doc
|
||||
: [].slice.call(arguments)
|
||||
.filter(function(e){ return e !== undefined })
|
||||
.slice(1)
|
||||
func = args.pop()
|
||||
last = args[args.length-1]
|
||||
attrs = last != null && typeof(last) != typeof('str') ? args.pop() : {}
|
||||
doc = typeof(args[0]) == typeof('str') ? args.shift() : null
|
||||
ldoc = typeof(args[0]) == typeof('str') ? args.shift() : null
|
||||
|
||||
// populate the action attributes...
|
||||
//meth.name = name
|
||||
Object.defineProperty(meth, 'name', {
|
||||
@ -388,6 +406,10 @@ function Action(name, doc, ldoc, func){
|
||||
// make introspection be a bit better...
|
||||
meth.toString = func.toString.bind(func)
|
||||
|
||||
// setup attrs...
|
||||
Object.keys(attrs)
|
||||
.forEach(function(k){ meth[k] = attrs[k] })
|
||||
|
||||
return meth
|
||||
}
|
||||
// this will make action instances behave like real functions...
|
||||
@ -1520,19 +1542,8 @@ function Actions(a, b){
|
||||
return
|
||||
}
|
||||
|
||||
var func = arg.pop()
|
||||
|
||||
// attrs...
|
||||
var last = arg[arg.length-1]
|
||||
var attrs = last != null && typeof(last) != typeof('str') ? arg.pop() : {}
|
||||
var ldoc = typeof(arg[1]) == typeof('str') ? arg[1] : null
|
||||
|
||||
// create a new action...
|
||||
var a = obj[k] = new Action(k, arg[0], ldoc, func)
|
||||
|
||||
// setup attrs...
|
||||
Object.keys(attrs)
|
||||
.forEach(function(k){ a[k] = attrs[k] })
|
||||
var a = obj[k] = Action(k, arg)
|
||||
})
|
||||
|
||||
if(proto != null){
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ig-actions",
|
||||
"version": "3.0.4",
|
||||
"version": "3.1.0",
|
||||
"description": "",
|
||||
"main": "actions.js",
|
||||
"scripts": {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user