• Gets the state of the container (an object).

    Function operation is a simple and "low-cost" read-only operation, evaluated immediately, causing no side effects. If possible, please prefer it over other ways of reading state (e.g useSelector() of key-value-state-container-react, which makes component re-render "listened to" attributes).

    Do not modify the returned (state) object, as it will not invoke listeners (callbacks) (registered with registerStateChangedCallback() or registerActionDispatchedCallback()).

    For modifying the state without sending actions, calling reducers and invoking listeners (callbacks), use updateStateContainer() (although it is not recommended).

    Example state (abstraction in memory):

    Object ("EV")
    +- "power" (object)
    | +- "currentConsumption" (number): 15
    | +- "rangeLeft" (number): 225
    +- "wheels" (array)
    +- "frontLeftPressure" (number): 2.2
    +- "frontRightPressure" (number): 2.2
    +- "backLeftPressure" (number): 2.1
    +- "backRightPressure" (number): 2.3

    Anti-pattern:

    const { power } = getContainer({ containerId: "ev-20214553" });
    // DO NOT DO THIS!
    power.currentConsumption = 0;

    To reiterate: modifying the state object returned by getContainer() function as described above won't invoke any state listeners (callbacks), moreover, might lead to unexpected behavior (in the client application).

    There is a dedicated (official) updateStateContainer() function for modifying the state container.

    Type Parameters

    • TState extends Object

    Parameters

    • args: {
          containerId: string;
          ignoreUnregistered?: boolean;
      }
      • containerId: string

        Unique id of the container.

      • Optional ignoreUnregistered?: boolean

        If true, the method will ignore the container that is not registered yet. If false, the method will throw an error in such case.

        Default

        false
        

    Returns TState

Generated using TypeDoc