Merge branch 'master' of github.com:flynx/actions.js

This commit is contained in:
Alex A. Naanou 2019-05-03 19:47:19 +03:00
commit ef5297413d
3 changed files with 182 additions and 150 deletions

View File

@ -217,9 +217,9 @@ The call diagram:
+ pre + pre + + post + post + + pre + pre + + post + post +
Action event handler: o-------x o-------x Action event handler: o-------x o-------x
v ^ v ^
Actions o-------x o-------x Actions: o-------x o-------x
v ^ v ^
Root Action o---|---x Root Action: o---|---x
``` ```
@ -255,19 +255,19 @@ Root Action o---|---x
**Action (event) handler** **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`: from `MetaActions`:
```javascript ```javascript
action_set.on('action_name', function(){ actionSet.on('action_name', function(){
// post code... // post code...
}) })
action_set.on('action_name.post', function(){ actionSet.on('action_name.post', function(){
// post code... // post code...
}) })
action_set.on('action_name.pre', function(){ actionSet.on('action_name.pre', function(){
// pre code... // pre code...
}) })
``` ```
@ -288,14 +288,11 @@ action_set.on('action_name.pre', function(){
**Alias** **Alias**
```javascript ```javascript
// ...
fullAlias: ['Alias to .full(..) action...', 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... // the alias code...
'full: "argument" 1'], 'full: "argument" 1'],
// ...
``` ```
- an action created by `Alias(..)`, - 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 `ActionSet / object` level methods while anything accessible from the
_action_ is build-in. _action_ is build-in.
1. Documentation generation and introspection (`MetaActions`) #### 1. Documentation generation and introspection (`MetaActions`)
``` ```
<action>.toString() <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(){ ... }) <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 This replaces / complements the standard JavaScript overloading
mechanisms (`Action`, `Actions`) mechanisms (`Action`, `Actions`)
@ -375,7 +373,7 @@ _action_ is build-in.
### Secondary action protocols: ### 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... Pre phase...
``` ```
@ -401,7 +399,7 @@ _action_ is build-in.
pre phase functions can return post phase functions). 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 This enables us to call a callback or another action (inner) between
the root action's (outer) pre and post stages. the root action's (outer) pre and post stages.
@ -434,15 +432,15 @@ _action_ is build-in.
// Implementation actions (inner)... // Implementation actions (inner)...
implementationAction1: [function(){ implementationAction1: [function(){
return this.protocolAction.chainApply(this, function(){ return this.protocolAction.chainApply(this, function(){
// ... ...
}, ..) }, ..)
}] }],
implementationAction2: [function(){ implementationAction2: [function(){
return this.protocolAction.chainApply(this, function(){ return this.protocolAction.chainApply(this, function(){
// ... ...
}, ..) }, ..)
}] }],
``` ```
Now calling any of the 'implementation' actions will execute code Now calling any of the 'implementation' actions will execute code
@ -463,7 +461,7 @@ _action_ is build-in.
really necessary. really necessary.
3. `.__call__` action / handler #### 3. `.__call__` action / handler
This action if defined is called for every action called. It behaves This action if defined is called for every action called. It behaves
like any other action but with a fixed signature, it always receives 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. an overhead on all the actions if not done carefully.
4. Action attributes #### 4. Action attributes
XXX XXX
@ -491,6 +489,38 @@ _action_ is build-in.
-> <value> -> <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: ### Alias protocols:

View File

@ -903,6 +903,7 @@ Action.prototype.post = function(context, data){
.forEach(function(func){ .forEach(function(func){
func.call(context) }) func.call(context) })
// top calls... // top calls...
if(context.__action_after_running){
if(context.__action_after_running[0] == null){ if(context.__action_after_running[0] == null){
;(context.__action_after_running[1] || []) ;(context.__action_after_running[1] || [])
.forEach(function(func){ .forEach(function(func){
@ -912,6 +913,7 @@ Action.prototype.post = function(context, data){
} else { } else {
context.__action_after_running = context.__action_after_running[0] context.__action_after_running = context.__action_after_running[0]
} }
}
return res return res
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "ig-actions", "name": "ig-actions",
"version": "3.22.0", "version": "3.22.2",
"description": "", "description": "",
"main": "actions.js", "main": "actions.js",
"scripts": { "scripts": {