Mixin: StateMachine

wp.media.controller. StateMachine

wp.media.controller.StateMachine A state machine keeps track of state. It is in one state at a time, and can change from one state to another. States are stored as models in a Backbone collection.
Since:
  • 3.5.0
Mixes In:
  • Backbone.Events
Source:

Extends

  • Backbone.Model

Methods


lastState()

Returns the previous active state. Call the `state()` method with no parameters to retrieve the current active state.
Since:
  • 3.5.0
Source:
Returns:
Returns a State model from the StateMachine collection.
Type
wp.media.controller.State

off()

Source:
Returns:
Returns itself to allow chaining.
Type
wp.media.controller.StateMachine

on()

Source:
Returns:
Returns itself to allow chaining.
Type
wp.media.controller.StateMachine

setState(id)

Sets the active state. Bail if we're trying to select the current state, if we haven't created the `states` collection, or are trying to select a state that does not exist.
Parameters:
Name Type Description
id string
Since:
  • 3.5.0
Source:
Fires:
  • wp.media.controller.State#event:deactivate
  • wp.media.controller.State#event:activate
Returns:
Returns itself to allow chaining.
Type
wp.media.controller.StateMachine

state(id)

Fetch a state. If no `id` is provided, returns the active state. Implicitly creates states. Ensure that the `states` collection exists so the `StateMachine` can be used as a mixin.
Parameters:
Name Type Description
id string
Since:
  • 3.5.0
Source:
Returns:
Returns a State model from the StateMachine collection.
Type
wp.media.controller.State

trigger()

Source:
Returns:
Returns itself to allow chaining.
Type
wp.media.controller.StateMachine