@kayelaa/canvas API - v0.2.15
    Preparing search index...

    Class KaylaInternalState<T>

    Read-only view of a piece of state managed by useState.

    Performance critical warning Frequent .set() calls inside useTick / usePaint loops will cause expensive component re-execution (refresh). → Use useSelf or useRef for position, velocity, timers, counters, etc. → Reserve useState for infrequent structural changes (health → 0, level up, isDead, etc.).

    Type Parameters

    • T

      Type of the stored value

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    Accessors

    Methods

    Constructors

    Properties

    alwaysRecall: boolean

    Accessors

    • get value(): T

      The current value of the state.

      Reading this property is always safe and does not trigger side effects.

      Returns T

    • get lastChanged(): number

      Timestamp (milliseconds since epoch) of the last time the state was changed via .set().

      Useful for dependency tracking or knowing when the value was last mutated.

      Returns number

    Methods

    • Adds a number to the current value (only available when T is number).

      Convenience method that calls .set(get() + added). Behaves exactly like .set() regarding refresh overhead.

      Parameters

      • this: KaylaState<number>
      • added: number

        Value to add

      • options: { recall?: boolean } = {}

        Optional control over refresh

        • Optionalrecall?: boolean

          Force refresh (default: false)

      Returns void

    • Multiplies the current value by a number (only available when T is number).

      Convenience method that calls .set(get() * multiplier). Behaves exactly like .set() regarding refresh overhead.

      Parameters

      • this: KaylaState<number>
      • added: number
      • multiplier: { recall?: boolean } = {}

        Value to multiply by

      Returns void

    • Updates the state value.

      If the new value differs from the current one (strict !== comparison), and either recall: true is passed or alwaysRecall was set at creation, this triggers a component refresh.

      Refreshing re-runs the entire component function, re-binds hooks, and may re-mount/unmount children — avoid in hot paths.

      Parameters

      • this: KaylaState<T>
      • s: T
      • newValue: { recall?: boolean } = {}

        The new state value

      Returns void