MViewStates
On this page
- MViewStates ⇐
Trait
- buildStates()
- setState(state, [options])
- _changeState(newState, oldState)
- updateFSState([options])
- setStateOnPropertyChange(state, propertyPath, [options])
- getState() ⇒
String
- inState(stateName) ⇒
boolean
- addStates(states)
- _createStates(states)
- _normalizeCompoundState(states) ⇒
string
- _getStatesOfCompoundState(compoundStateName) ⇒
Array
MViewStates ⇐ Trait
Add states feature to View’s The View must support the ‘states’ class keyword and build the states in constructor by calling the buildStates method.
Kind: global mixin
Extends: Trait
Properties
Name | Type | Description |
---|---|---|
$$state | String | Internal, read only ! - the current state |
$$triggers | Object | Internal, read only ! a map to the currently watched properties for triggering states |
- MViewStates ⇐
Trait
- .buildStates()
- .setState(state, [options])
- ._changeState(newState, oldState)
- .updateFSState([options])
- .setStateOnPropertyChange(state, propertyPath, [options])
- .getState() ⇒
String
- .inState(stateName) ⇒
boolean
- .addStates(states)
- ._createStates(states)
- ._normalizeCompoundState(states) ⇒
string
- ._getStatesOfCompoundState(compoundStateName) ⇒
Array
buildStates()
Build the states map. Must be called once when the View is constructed.
Kind: instance method of MViewStates
setState(state, [options])
Set the new state Trigger event “change.state” only if the state has changed
// "default: { x: 10, y: 10, opacity:0, color: "#000000" }
// "stateA: { x: 500, opacity:0.5 }
// "stateB: { y: 500, opacity:1 }
// "stateA&stateB": { color: "#ffffff" }
// or "stateB&stateA"
view.setState("stateA"); // x=500, y=10, opacity=1, color: "#000000"
view.setState("stateB"); // x=10, y=500, opacity=1, color: "#000000"
view.setState("stateA&stateB"); // x=500, y=500, opacity=1, color: "#ffffff"
view.setState("stateB&stateA"); // x=500, y=500, opacity=0.5, color: "#ffffff"
Kind: instance method of MViewStates
Param | Type | Description |
---|---|---|
state | string | The new state |
[options] | Object | Additional options |
[options.skipNotify] | boolean | If true do not fire the "change.state" event |
[options.skipTransitions] | boolean | If true do not play the transitions |
[options.force] | boolean | If true, the state is set even if it is already in this state (reset) |
[options.delay] | number | apply the properties values after the delay; for transitions, will add the delay to the animations |
_changeState(newState, oldState)
Extension point Use it to set the states of the children These method will be deprecated when ‘state’ will be a property, ie when the writting of
"states": {
"selected": {
"myChild.state": "selected"
}
}
will be supported
As of writting, you need to write it like this
Kind: instance method of MViewStates
Access: protected
Param | Type | Description |
---|---|---|
newState | string | the new applied state |
oldState | string | the previous state |
Example
_changeState: function() {
if(this.inState("selected")) {
this.myChild.setState("selected");
}
}
updateFSState([options])
Apply a setState with current state to update focus and selected state
Kind: instance method of MViewStates
Param | Type |
---|---|
[options] | Object |
setStateOnPropertyChange(state, propertyPath, [options])
Change the state when the value of the property change. You can choose the targeted state depending on the value of the property.
Kind: instance method of MViewStates
Param | Type | Description |
---|---|---|
state | string | function | The name of the state or a function that returns it - callback that takes a data (data.value, data.oldValue) in args - if the callback returns null the state is not changed |
propertyPath | string | The name of the object property, or of one of it's children property ("childId.propertyName") |
[options] | Object | Additional options See #setState for common options |
Example
setStateOnPropertyChange("state", "propertyPath")
setStateOnPropertyChange(data => data.value === true ? "state" : null, "propertyPath" )
setStateOnPropertyChange(data => data.value === true ? "state" : "default", "propertyPath")
getState() ⇒ String
Return the array of states of the view or the state if not a compound state
Kind: instance method of MViewStates
inState(stateName) ⇒ boolean
Return the true if the view is in the state.
Kind: instance method of MViewStates
Returns: boolean
- true if the view is in the state
Param | Type | Description |
---|---|---|
stateName | string | The state name |
addStates(states)
Dynamically add states definition
Kind: instance method of MViewStates
Param | Type | Description |
---|---|---|
states | Object | The states definition, as defined in the class declaration |
_createStates(states)
Read the states definition and copy it to the internal states object property
Kind: instance method of MViewStates
Access: protected
Param | Type | Description |
---|---|---|
states | Object | The definition of the states |
_normalizeCompoundState(states) ⇒ string
Normalize the name of a compound state, so that “stateA&stateB” and ‘stateB&stateA" refers to the same name The way it is normalized should have no consequence at all on the states functionality
Kind: instance method of MViewStates
Access: protected
Param | Type | Description |
---|---|---|
states | Array.<string> | An array of states composing the compound state |
_getStatesOfCompoundState(compoundStateName) ⇒ Array
Return an array of states composed by the compound state /!\ IMPORTANT /!\ focused always at last
Kind: instance method of MViewStates
Access: protected
Param | Type | Description |
---|---|---|
compoundStateName | string | The compound state, state names linked with a "&" (eg "stateA&stateB") |