Mixin

mxui/mixin/_Stateful

mxui/mixin/_Stateful

This mixin allows widgets to store their state just before another page is opened in content. When the user navigates back to the page and the widget is recreated, it can retrieve the previously stored state.

State is stored and retrieved using a key for reference. This key does not have to be unique between widget instances.

Methods

# getState(keynullable, defnullable)

Retrieve state associated with this widget in this page.

Parameters:
Name Type Attributes Description
key string <nullable>

key under which the state has been stored. If not specified, all state is returned in an object.

def * <nullable>

default value to return when no state has been stored under the key

the value previously stored under key if available, def otherwise

Example
// Retrieve previous collapsed state if available, otherwise return false.
this.collapsed = this.getState("collapsed", false);

# abstract storeState(store)

Called whenever the current page is closed before transitioning to the next. It is an error not to implement this method.

Parameters:
Name Type Description
store mxui/mixin/_Stateful~StoreFunction

function used to store the current state

Type Definitions

# StoreFunction(key, value)

Function used to store the state in mxui/mixin/_Stateful#storeState.

Parameters:
Name Type Description
key string

key under which to store the state

value *

value to store under the given key