Constructor
new State(app, routeParamsopt, parentStateopt)
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
app | App | App instance | ||
routeParams | RouteParams | <optional> | Current route params | |
parentState | State | <optional> | null | Parent state for sub-states |
- Source
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.
- string |
null
- Source
ROUTE :string|array
Route(s) which trigger this state
- string |
array
- Source
Methods
addEventListener(target, type, listener, options)
Add event listener with automatic cleanup tracking
Name | Type | Default | Description |
---|---|---|---|
target | EventTarget | Event target (element, window, document, etc.) | |
type | string | Event type | |
listener | function | Event listener function | |
options | boolean | | false | Event listener options |
- Source
canEnter() → {boolean}
Called before entering state.
- Source
- Type:
- boolean
canExit() → {boolean}
Called before exiting state. Return false to prevent state transition. Also checks if sub-states can exit.
- Source
- True to allow exit, false to prevent exit
- Type:
- boolean
clearInterval(intervalId)
Clear specific interval
Name | Type | Description |
---|---|---|
intervalId | number | Interval ID to clear |
- Source
clearTimeout(timeoutId)
Clear specific timeout
Name | Type | Description |
---|---|---|
timeoutId | number | Timeout ID to clear |
- Source
(async) createSubStateManager() → {Promise.<StateManager>}
Create a sub-state manager for nested states
- Source
Sub-state manager instance
- Type:
- Promise.<StateManager>
(async) dispose() → {Promise.<void>}
Dispose of the state and cleanup all resources Called automatically by StateManager when exiting state Handles hierarchical cleanup of sub-states Override onDispose() for custom cleanup logic
- Source
- Type:
- Promise.<void>
(async) enter() → {Promise.<void>}
Called when entering scene and after canEnter() call returned true.
- Source
- Type:
- Promise.<void>
(async) exit() → {Promise.<void>}
Called when exiting scene and after canExit() call return true. Also handles sub-state cleanup.
- Source
- Type:
- Promise.<void>
findStateInHierarchy(stateId, visited) → {State|null}
Find a state in the hierarchy by ID
Name | Type | Description |
---|---|---|
stateId | string | State ID to find |
visited | Set | Set of already visited states (internal use) |
- Source
Found state or null
- Type:
- State |
null
getCurrentSubState() → {State|null}
Get current sub-state
- Source
- Type:
- State |
null
getFullStatePath() → {Array.<string>}
Get full state path including current sub-state
- Source
Complete path including sub-states
- Type:
- Array.<string>
getId() → {string}
Return current ID
- Source
- Type:
- string
getRedirectUrl() → {string|null}
Called when canEnter() function returns false.
- Source
- Return redirect route.
- Type:
- string |
null
getRootState() → {State}
Get the root state (top-level parent)
- Source
- Type:
- State
getStateData() → {*}
Get data for this state
- Source
- State data
- Type:
- *
getStatePath() → {Array.<string>}
Get state path (hierarchy chain)
- Source
Array of state IDs from root to current
- Type:
- Array.<string>
hasActiveSubState() → {boolean}
Check if this state has an active sub-state
- Source
- Type:
- boolean
hasSubStates() → {boolean}
Check if this state has sub-states
- Source
- Type:
- boolean
isDisposed() → {boolean}
Check if state has been disposed
- Source
True if state is disposed
- Type:
- boolean
onCanExit() → {boolean}
Override this method for custom exit validation logic
- Source
- True to allow exit, false to prevent exit
- Type:
- boolean
(async) onDispose() → {Promise.<void>}
Override this method for custom cleanup logic Called before automatic resource cleanup in dispose()
- Source
- Type:
- Promise.<void>
(async) onEnter() → {Promise.<void>}
Override this method for custom enter logic
- Source
- Type:
- Promise.<void>
(async) onExit() → {Promise.<void>}
Override this method for custom exit logic
- Source
- Type:
- Promise.<void>
removeEventListener(target, type, listener, options)
Remove specific event listener
Name | Type | Default | Description |
---|---|---|---|
target | EventTarget | Event target | |
type | string | Event type | |
listener | function | Event listener function | |
options | boolean | | false | Event listener options |
- Source
setInterval(callback, delay) → {number}
Set interval with automatic cleanup tracking
Name | Type | Description |
---|---|---|
callback | function | Callback function |
delay | number | Delay in milliseconds |
- Source
Interval ID
- Type:
- number
setStateData(data)
Set data for this state (used for data transfer between states)
Name | Type | Description |
---|---|---|
data | * | Data to set |
- Source
setTimeout(callback, delay) → {number}
Set timeout with automatic cleanup tracking
Name | Type | Description |
---|---|---|
callback | function | Callback function |
delay | number | Delay in milliseconds |
- Source
Timeout ID
- Type:
- number
(async) switchToSubState(subStateId, stateData) → {Promise.<boolean>}
Switch to a sub-state
Name | Type | Default | Description |
---|---|---|---|
subStateId | string | Sub-state ID to switch to | |
stateData | * | null | Data to pass to sub-state |
- Source
- Type:
- Promise.<boolean>