new Action(var_args)
Manage a node and associated subset of the action graph
Name | Type | Description |
---|---|---|
var_args |
Action | Array | Object | repeatable (arrays of) promises to fire |
Example
var my_action = new Action(
'Action title', // used to make debugging data more readable
// pass a list of promises that will be executed
{
fire: function() { // called by action.fire()
return $.post(...);
},
description: function() { // optional: return debugging information
return [
{ type: "PM", target: {username: 'Joe Bloggs', user_id: 12345 } },
];
},
blockers: function() {
return [ 'Message describing how to resolve the thing blocking the action' ];
},
},
// further promises will be executed in parallel:
new Action(...),
[ { ... }, new Action(...) ], // arrays are expanded automatically
// ...
);
Methods
-
blockers(){Array.<string>}
list of things blocking the action from firing
-
Returns:
Type Description Array.<string> list of blockers -
fire(bb, keys){jQuery.Promise}
fire the graph of actions starting with this one
-
the promise will be resolved when the final action is resolved, or rejected shortly after the first action fails (ongoing requests will be allowed to finish). progress() will be called regularly with a fraction representing the completeness of the complete set of actions.
Name Type Description bb
BulletinBoard BulletinBoard keys
Object keys to pass to all actions Returns:
Type Description jQuery.Promise promise representing the full graph of actions -
fire_with_journal(bb, keys, v, thread_id, namespace, name, extra_bbs){jQuery.Promise}
call fire(), with values logged to a journal post
-
To improve the audit trail for large actions, you might want to record the action you're about to perform, perform the action, then record the outcome. This function posts a reply to a thread, calls .fire(), then edits the post when .fire() completes. Posts will be constructed using variables named [ name + ( ' title' or ' body' ), 'before' or 'after' ], e.g. [ name+' title', 'before' ] will be used to get the title for the "before" post.
Name Type Description bb
BulletinBoard BulletinBoard keys
Object keys to pass to all actions v
Variables object to retrieve variables from thread_id
Number thread to post the journal in namespace
string namespace to retrieve journal variables from name
name unique name of this action extra_bbs
Array.<BulletinBoard> other BulletinBoards to check before firing Returns:
Type Description jQuery.Promise promise representing the full graph of actions -
long_description(){string}
Long description of actions that will be performed (suitable for debugging use)
-
Returns:
Type Description string long description -
then(actions){Action}
add another action that will fire after this completes
-
This mimics jQuery's "then" API, but we currently modify the existing action instead of returning a new one. This was an implementation shortcut and might be fixed if we find a use for the full behaviour
Name Type Description actions
Action repeatable actions to add Returns:
Type Description Action the current action -
title(){Array.<string>}
describe the graph of actions starting with this one
-
Returns:
Type Description Array.<string> short descriptions