mirror of
https://github.com/flynx/actions.js.git
synced 2025-10-29 02:10:09 +00:00
Merge branch 'master' of github.com:flynx/actions.js
This commit is contained in:
commit
ef5297413d
74
README.md
74
README.md
@ -217,9 +217,9 @@ The call diagram:
|
||||
+ pre + pre + + post + post +
|
||||
Action event handler: o-------x o-------x
|
||||
v ^
|
||||
Actions o-------x o-------x
|
||||
Actions: o-------x o-------x
|
||||
v ^
|
||||
Root Action o---|---x
|
||||
Root Action: o---|---x
|
||||
|
||||
```
|
||||
|
||||
@ -255,19 +255,19 @@ Root Action o---|---x
|
||||
|
||||
**Action (event) handler**
|
||||
|
||||
When `action_set` object is inherited from a `ActionSet` object or
|
||||
When `actionSet` object is inherited from a `ActionSet` object or
|
||||
from `MetaActions`:
|
||||
```javascript
|
||||
action_set.on('action_name', function(){
|
||||
actionSet.on('action_name', function(){
|
||||
// post code...
|
||||
})
|
||||
|
||||
action_set.on('action_name.post', function(){
|
||||
actionSet.on('action_name.post', function(){
|
||||
// post code...
|
||||
})
|
||||
|
||||
|
||||
action_set.on('action_name.pre', function(){
|
||||
actionSet.on('action_name.pre', function(){
|
||||
// pre code...
|
||||
})
|
||||
```
|
||||
@ -288,14 +288,11 @@ action_set.on('action_name.pre', function(){
|
||||
**Alias**
|
||||
|
||||
```javascript
|
||||
// ...
|
||||
|
||||
fullAlias: ['Alias to .full(..) action...',
|
||||
'This alias will call the .full(..) action and pass it a couple of arguments',
|
||||
`This alias will call the .full(..) action and pass it a couple of
|
||||
arguments`,
|
||||
// the alias code...
|
||||
'full: "argument" 1'],
|
||||
|
||||
// ...
|
||||
```
|
||||
|
||||
- an action created by `Alias(..)`,
|
||||
@ -318,7 +315,7 @@ from an instance of `ActionSet`. In general this includes all
|
||||
`ActionSet / object` level methods while anything accessible from the
|
||||
_action_ is build-in.
|
||||
|
||||
1. Documentation generation and introspection (`MetaActions`)
|
||||
#### 1. Documentation generation and introspection (`MetaActions`)
|
||||
|
||||
```
|
||||
<action>.toString()
|
||||
@ -336,7 +333,7 @@ _action_ is build-in.
|
||||
```
|
||||
|
||||
|
||||
2. Event-like callbacks for actions (`MetaActions`, `Action`)
|
||||
#### 2. Event-like callbacks for actions (`MetaActions`, `Action`)
|
||||
|
||||
```
|
||||
<action-set>.on('action', function(){ ... })
|
||||
@ -346,7 +343,8 @@ _action_ is build-in.
|
||||
```
|
||||
|
||||
|
||||
3. A mechanism to define and extend already defined actions
|
||||
#### 3. A mechanism to define and extend already defined actions
|
||||
|
||||
This replaces / complements the standard JavaScript overloading
|
||||
mechanisms (`Action`, `Actions`)
|
||||
|
||||
@ -375,7 +373,7 @@ _action_ is build-in.
|
||||
|
||||
### Secondary action protocols:
|
||||
|
||||
1. A mechanism to manually call the pre/post stages of an action
|
||||
#### 1. A mechanism to manually call the pre/post stages of an action
|
||||
|
||||
Pre phase...
|
||||
```
|
||||
@ -401,7 +399,7 @@ _action_ is build-in.
|
||||
pre phase functions can return post phase functions).
|
||||
|
||||
|
||||
2. A mechanism to chain/wrap actions or an action and a function.
|
||||
#### 2. A mechanism to chain/wrap actions or an action and a function.
|
||||
This enables us to call a callback or another action (inner) between
|
||||
the root action's (outer) pre and post stages.
|
||||
|
||||
@ -434,15 +432,15 @@ _action_ is build-in.
|
||||
// Implementation actions (inner)...
|
||||
implementationAction1: [function(){
|
||||
return this.protocolAction.chainApply(this, function(){
|
||||
// ...
|
||||
...
|
||||
}, ..)
|
||||
}]
|
||||
}],
|
||||
|
||||
implementationAction2: [function(){
|
||||
return this.protocolAction.chainApply(this, function(){
|
||||
// ...
|
||||
...
|
||||
}, ..)
|
||||
}]
|
||||
}],
|
||||
```
|
||||
|
||||
Now calling any of the 'implementation' actions will execute code
|
||||
@ -463,7 +461,7 @@ _action_ is build-in.
|
||||
really necessary.
|
||||
|
||||
|
||||
3. `.__call__` action / handler
|
||||
#### 3. `.__call__` action / handler
|
||||
|
||||
This action if defined is called for every action called. It behaves
|
||||
like any other action but with a fixed signature, it always receives
|
||||
@ -479,7 +477,7 @@ _action_ is build-in.
|
||||
an overhead on all the actions if not done carefully.
|
||||
|
||||
|
||||
4. Action attributes
|
||||
#### 4. Action attributes
|
||||
|
||||
XXX
|
||||
|
||||
@ -491,6 +489,38 @@ _action_ is build-in.
|
||||
-> <value>
|
||||
```
|
||||
|
||||
#### 5. Scheduling a call after the running action
|
||||
|
||||
This enables the action code to schedule a call after the current
|
||||
action level or the root action is done.
|
||||
|
||||
```
|
||||
<action-set>.afterAction(func)
|
||||
<action-set>.afterAction('top', func)
|
||||
-> this
|
||||
|
||||
<action-set>.afterAction('local', func)
|
||||
-> this
|
||||
```
|
||||
|
||||
Example:
|
||||
```javascript
|
||||
someAction: [
|
||||
function(){
|
||||
...
|
||||
|
||||
// the function passed will get called after the root action
|
||||
// and all it's handlers are done.
|
||||
this.afterAction(function(){ ... })
|
||||
|
||||
...
|
||||
}],
|
||||
```
|
||||
|
||||
**Notes:**
|
||||
- The functions are executed in order of registration.
|
||||
- This is pointless outside of an action call, this an exception will be thrown.
|
||||
|
||||
|
||||
### Alias protocols:
|
||||
|
||||
|
||||
@ -903,6 +903,7 @@ Action.prototype.post = function(context, data){
|
||||
.forEach(function(func){
|
||||
func.call(context) })
|
||||
// top calls...
|
||||
if(context.__action_after_running){
|
||||
if(context.__action_after_running[0] == null){
|
||||
;(context.__action_after_running[1] || [])
|
||||
.forEach(function(func){
|
||||
@ -912,6 +913,7 @@ Action.prototype.post = function(context, data){
|
||||
} else {
|
||||
context.__action_after_running = context.__action_after_running[0]
|
||||
}
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ig-actions",
|
||||
"version": "3.22.0",
|
||||
"version": "3.22.2",
|
||||
"description": "",
|
||||
"main": "actions.js",
|
||||
"scripts": {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user