State

State class. Parent state class. Extend this class for your state logic.

Constructor

new State(app, routeParamsopt)

Parameters:
NameTypeAttributesDescription
appApp

App instance

routeParamsRouteParams<optional>

Current route params

Example
Create a state called MyState with is executed when the url 'my-state' is called. When executed,
it prints 'Hello from MyState' to the console.

class MyState extends State
{
    asnyc enter()
    {
        console.log( "Hello from MyState" );
    }
}

Members

ID :string|null

ID of state. Should be an unique identifier. If not set it will be auto-generated.

Type:
  • string | null

ROUTE :string|array

Route(s) which trigger this state

Type:
  • string | array

Methods

canEnter() → {boolean}

Called before entering state.

Returns:
Type: 
boolean

canExit() → {boolean}

Called before exiting state.

Returns:
Type: 
boolean

(async) enter() → {Promise.<void>}

Called when entering scene and after canEnter() call returned true.

Returns:
Type: 
Promise.<void>

(async) exit() → {Promise.<void>}

Called when exiting scene and after canExit() call return true.

Returns:
Type: 
Promise.<void>

getId() → {string}

Return current ID

Returns:
Type: 
string

getRedirectUrl() → {string|null}

Called when canEnter() function returns false.

Returns:
  • Return redirect route.
Type: 
string | null