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).
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.
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()
ofkey-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()
orregisterActionDispatchedCallback()
).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):
Anti-pattern:
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.