ProAct.Queue Class
src/js/flow/queue.js:5
Creates a queue of actions or action queue.
The idea of the action queues is to decide the order of the actions pushed into them. For example if an action should be executed only once, but is pushed for a second time, it is moved in the end of the queue and its parameters are updated.
The ProAct.Queue is a priority queue, meaning every action has a numeric priority. The actions with the numerically lowest priority are with highes prority when executed.
The go method deques all the actions from the queue and executes them in the right order, using their priorities.
A ProAct.Queue can be used to setup the action flow - the order of the actions must be executed. ProAct.js uses it to create an action flow if something changes.
TODO Default name should be extracted to a constant. ~meddle@2014-07-10
Constructor
ProAct.Queue
-
name -
options
Parameters:
-
nameStringThe name of the queue, every ProAct.Queue must have a name. The default value of the name is 'proq'. ProAct.Queues uses the names to manage its queues.
-
optionsObject
Methods
go
-
once
Starts the action flow.
Executes the actions in this queue in the order they were enqued, but also uses the priorities to execute these with numerically higher priority after these with numerically lower priority.
If some of the actions enques new actions in this queue and the parameter once is set to false this method is recursively called executing the new actions.
run is alias of this method.
Parameters:
-
onceBooleanTrue if 'go' should not be called for actions generated by the executed ones.
isEmpty
()
Boolean
Checks if this ProAct.Queue is empty.
Returns:
True if there are no actions in this queue.
length
()
Number
Retrieves the lenght of this ProAct.Queue.
Returns:
The number of actions queued in this queue.
push
-
context -
action -
args
Pushes an action to this queue. This method can enque the same action multiple times and always with priority of '1'.
defer, enque and add are aliases of this method.
Parameters:
-
contextObjectThe context of the action. It can be null.
If the method is called with a Function context, the context becomes the action. This way the method can be called with only one parameter for actions without context.
-
actionFunctionThe action to enque.
If there is no context and the action is passed in place of the context, this parameter can hold the arguments of the action.
-
argsArrayArguments to be passed to the action when it is executed.
pushOnce
-
context -
action -
args
Pushes an action to this queue only once.
If the action is pushed for the second time using this method, instead of adding it to the queue, its priority goes up and its arguments are updated. This means that this action will be executed after all the other actions, pushed only once.
deferOnce, enqueOnce and addOnce are aliases of this method.
Parameters:
-
contextObjectThe context of the action. It can be null.
If the method is called with a Function context, the context becomes the action. This way the method can be called with only one parameter for actions without context.
-
actionFunctionThe action to enque.
If there is no context and the action is passed in place of the context, this parameter can hold the arguments of the action.
-
argsArrayArguments to be passed to the action when it is executed.
runAction
-
queue -
context -
action -
args -
errHandler
Executes the passed action.
Parameters:
-
queueProAct.QueueThe queue managing the action to execute.
-
contextObjectThe context in which the action should be executed.
The action is a normal JavaScript function and the context is the object that should be bound to this when calling it.
It can be null or undefined.
-
actionFunctionThe action to execute.
-
argsArrayThe parameters to be passed to the action.
-
errHandlerFunctionIt is called if an error is thrown when executing the action.
It can be null if the error should be catched from the outside.
proact.js