mixins/state¶
-
mixin
StateMixin()¶ Mixin that defines the state getter and loader.
-
read-only
state¶ Type: StateProxy The object managing the state,
-
read-only
-
class
StateProxy(base)¶ Extends: Emitter Provides the state handling functions.
Warning
There is no need to instanciate this object directly, this is all handled by the state mixin.
Arguments: - base (Emitter) – The instance of which the state is managed. Used for informing it about state changes.
-
read-only
obj¶ Type: Object The object holding the state information. Manipulating its values will not cause the appropriate events to be emitted.
-
read-only
base¶ Type: Emitter The instance of which the state is managed.
-
get(stateKey[, defaultValue])¶ Retieves the value of a state. Returns undefined if it is not set.
Arguments: - stateKey (String) – The key of the value to be retrieved.
- defaultValue (Any) – The value to return if the given state key is not defined.
Returns: The value for the given stateKey.
Return type: Any
-
set(stateKey, value[, delay])¶ - Sets the value of a state key, then triggers the events in the order they are documented in. Finally calls
save()and returns the final value.Arguments: - stateKey (String) – The key of the valuze to set.
- value (Any) – The value to set. Must be serializable by JSON to be saved.
- delay (Number) –
save()is called with this paramerter.
Returns: The new value for the stateKey. (This may actuall differ from what was intendet to be set, if it was changed during the events.)
Return type: Any
Emits *stateKey*(newValue, oldValue)*stateKey*(newValue, oldValue): Events of the appropriate stateKey will be emitted when its value changed.
Emits changedState(stateKey, newValue, oldValue): Is emitted for state changes - but on the base object.
-
setup(source[, auxSource])¶ Will update the internal state with the values from the given parameters.
Arguments: - source (Object) – An object containing the values to apply to the state.
- auxSource (Object) – An additonal object containing the values to apply to the state.
Emits changedState(null)null): Is always emitted afterwards - but on the base object.