Show:
Defined in: src/js/flow/flow.js:9
Module: proact-flow

Constructs the action flow of the ProAct.js; An action flow is a set of actions executed in the reactive environment, which order is determined by the dependencies between the reactive properties. The action flow puts on motion the data flow in the reactive ecosystem. Every change on a property triggers an action flow, which triggers the data flow.

ProAct.Flow is inspired by the Ember's Backburner.js (https://github.com/ebryn/backburner.js). The defferences are the priority queues and some other optimizations like the the 'once' argument of the go method. It doesn't include debouncing and timed defer of actions for now.

ProAct.Flow is used to solve many of the problems in the reactive programming, for example the diamond problem.

It can be used for other purposes too, for example to run rendering in a rendering queue, after all of the property updates.

ProAct.Flow, ProAct.Queues and ProAct.Queue together form the proact-flow module of ProAct.

TODO ProAct.Flow#start and ProAct.Flow#stop are confusing names - should be renamed to something like 'init' and 'exec'.

Constructor

ProAct.Flow

(
  • queueNames
  • options
)

Parameters:

  • queueNames Array

    Array with the names of the sub-queues of the ProAct.Queueses of the flow. The size of this array determines the number of the sub-queues.

  • options Object

    Various options for the ProAct.Flow.

    Available options:

    • start - A callback that will be called every time when the action flow starts.
    • stop - A callback that will be called every time when the action flow ends.
    • err - A callback that will be called if an error is thrown in the action flow.
    • flowInstance - Options object for the current flow instance. The flow instances are of the class ProAct.Queues.

Methods

addQueue

(
  • queueName
)

Appends a new queue name to the list of this' queues.

When a new flowInstance is created the updated list will be used.

Parameters:

  • queueName String

    The queue name to add.

isPaused

()

Checks if this ProAct.Flow is paused.

isRunning

()

Checks if there is an active ProAct.Queues instance in this ProAct.Flow.

TODO This should be named 'isActive'.

pause

()

Puts the flow in pause mode. When the flow is paused actions that should be defered to be run in it are skipped.

push

(
  • queueName
  • context
  • action
  • args
)

Pushes an action to the flow. This method can defer in the flow the same action multiple times.

defer, enque and add are aliases of this method.

If the flow is paused, the action will not be defered.

TODO Errors should be put in constants!

Parameters:

  • queueName String

    The name of the queue to defer the action in.

    On the place of this argument the context can be passed and the queue to push in becomes the first queue available.

  • context Object

    The 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 Function

    The action to defer into the flow.

    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 Array

    Arguments to be passed to the action when it is executed.

pushOnce

(
  • queueName
  • context
  • action
  • args
)

Defers an action to the flow only once per run.

If the action is pushed for the second time using this method, instead of adding it, its set to be executed later then all the actions that were defered only once, using this method.

deferOnce, enqueOnce and addOnce are aliases of this method.

If the flow is paused, the action will not be defered.

Parameters:

  • queueName String

    The name of the queue to defer 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 Object

    The 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 Function

    The action to defer.

    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 Array

    Arguments to be passed to the action when it is executed.

resume

()

Resumes the action flow if it is paused. The flow becomes active again and actions can be pushed into it.

run

(
  • context
  • callback
)

Starts the action flow, executes the passed callback, in the passed context, and then stops the action flow, executing all the pushed by the callback actions.

This means that you are guaranteed that you have a running action flow for the actions that should be pushed to a flow in the callback.

go and flush are aliases of this method.

Parameters:

  • context Object

    The value of this bound to the callback when it is executed.

  • callback Function

    The callback that will be invoked in a new running ProAct.Flow.

setQueues

(
  • queueNames
)

Sets the queue names of this flow.

When a new flowInstance is created the new list will be used.

Parameters:

  • queueNames Array

    Array with the names of the sub-queues of the ProAct.Queueses of the flow. The size of this array determines the number of the sub-queues.

start

()

Puts the ProAct.Flow in running mode, meaning actions can be defered in it.

It creates a new flow instance - instance of ProAct.Queues and if there was a running instance, it is set to be the previous inctance.

If a start callback was passed when this ProAct.Flow was being created, it is called with the new flow instance.

begin is alias of this method.

stop

()

Starts an action flow consisting of all the actions defered after the last call of start and then stops the ProAct.Flow.

If there is a current action flow instance, it is flushed, using the go method.

If there was aprevious flow instance, it is set to be the current one.

If a callback for 'stop' was specified in the options on creation, it is called with the flushed instance.

When the flow is started you put actions in order or with priority, and if you want to execute them and stop it, you call this method.

end is an alias for this method.

Properties

constructor

ProAct.Flow final

Reference to the constructor of this object.