ProAct.Queues Class
src/js/flow/queues.js:5
Creates a queue of ProAct.Queues. The order of these sub-queues is used to determine the order in which they will be dequed.
The idea of this class is to have different queues for the different layers of an application. That way lower level actions will always execuded before higher level.
If a higher level queue enques actions in lower level one, the action flow returns stops and returns from the lower level one.
The go method deques all the actions from all the queues and executes them in the right order, using their priorities and queue order.
A ProAct.Queues
can be used to setup very complex the action flow.
ProAct.js uses it with only one queue - 'proq' to create an action flow if something changes.
TODO We need to pass before, after and error callbacks here too. ~meddle@2014-07-10
Constructor
ProAct.Queues
-
queueNames
-
options
Parameters:
-
queueNames
ArrayArray with the names of the sub-queues. The size of this array determines the number of the sub-queues.
-
options
ObjectVarious options for the ProAct.Queues.
Available options:
- queue - An options object containing options to be passed to all the sub-queues. For more information see ProAct.Queue.
Methods
go
-
queueName
Starts the action flow.
Executes the actions in all the sub-queues 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 in the third queue pushes new actions to the second queue, the action flow returns to the second queue again and then continues through all the queues.
run
and flush
are aliases of this method.
Parameters:
-
queueName
StringThe name of the queue to begin from. Can be null and defaults to the first sub-queue.
isEmpty
()
Boolean
Checks if this ProAct.Queues
is empty.
Returns:
True if there are no actions in any of the sub-queues.
push
-
queueName
-
context
-
action
-
args
Pushes an action to a sub-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:
-
queueName
StringThe name of the queue to enque the action in.
On the place of this argument the context can be passed and the queue to push in becomes the first queue of the sub-queues.
-
context
ObjectThe 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.
-
action
FunctionThe 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.
-
args
ArrayArguments to be passed to the action when it is executed.
pushOnce
-
queueName
-
context
-
action
-
args
Pushes an action to a sub-queue only once.
If the action is pushed for the second time using this method, instead of adding it to the sub-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:
-
queueName
StringThe name of the queue to enque the action in.
On the place of this argument the context can be passed and the queue to push in becomes the first queue of the sub-queues.
-
context
ObjectThe 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.
-
action
FunctionThe 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.
-
args
ArrayArguments to be passed to the action when it is executed.