Class GouterState<T, N>

Tree-like structure with name, params and stack to build complex navigation. Has useful methods to access and control each part.

Type Parameters

Constructors

  • Creates GouterState using required name, params and optional stack.

    Type Parameters

    Parameters

    • name: N

      string to distinguish states

    • params: T[N]

      collection of parameters to customize states

    • Optional stack: GouterState<T, keyof T>[]

      optional list of inner states

    • Optional focusedIndex: number

      optional index of focused state in stack

    Returns GouterState<T, N>

Properties

focusedIndex: number
name: N
params: T[N]
stack: GouterState<T, keyof T>[]
emptyStack: GouterState<any, string | number | symbol>[]

Empty stack for internal state initialization only.

focusingStates: WeakSet<GouterState<GouterConfig, any>>

Set of states which will be focused when put into a stack.

listenersByState: WeakMap<GouterState<GouterConfig, any>, Set<GouterListener<any, any>>>

Listeners of each state.

modifiedStates: Set<GouterState<GouterConfig, any>>

Collection of modified states controlled by schedule and notify functions.

parentByState: WeakMap<GouterState<GouterConfig, any>, GouterState<any, string | number | symbol>>

Parents of each state.

rootStates: WeakSet<GouterState<any, string | number | symbol>>

Set of special states which are focused when they have no parent.

schedulerReady: boolean

To check if new scheduler promise could be created. When that promise resolves, each modified state listeners will be called.

Accessors

  • get isFocused(): boolean
  • True when this state has a parent and it's focusedIndex points to this state.

    Returns boolean

Methods

  • Focuses on this state by recursively changing focusedIndex of it's parents. If it has no parent or parent focusedIndex is same then nothing happens.

    Returns GouterState<T, N>

  • Adds this listener of router state changes to set of listeners and returns unlisten callback. Every listener will be called on each update of params, stack and/or focusedIndex.

    Parameters

    Returns (() => void)

    unlisten callback

      • (): void
      • Returns void

  • Focuses on stack state with provided focusedIndex. If that index is same as before or stack state is not found then nothing happens.

    Parameters

    • focusedIndex: number

    Returns GouterState<T, N>

  • Replaces current stack. It also resets current focusedIndex to last stack state index so if you need to preserve or modify that index you should call focus on some stack state before this operation. If some state in new stack already has parent then it will be cloned using clone.

    Parameters

    Returns GouterState<T, N>

  • Adds this state to special set of focusing states. During parent setStack call it will be automatically focused only once and then removed from focusing states. If two or more focusing states occur in same stack then last one will be focused.

    Returns GouterState<T, N>

Generated using TypeDoc