Store concepts in detail
Note that attempting to access state is not supported in IE11 and will immediately throw an error.
The StoreProvider accepts three properties
renderer
: A render function that has the store injected to access state and pass processes to child widgets.stateKey
: The key of the state in the registry.paths
(optional): A function to connect the provider to sections of the state.
The StoreProvider
has two main ways to trigger invalidation and cause a rerender.
- The recommended approach is to register
path
s by passing the property to the provider to ensure invalidation only occurs when relevant state changes. - A catch-all when no
path
s are defined for the container, it will invalidate when any data changes in the store.
A Process
has an execution lifecycle that defines the flow of the behavior being defined.
- If a transformer is present it gets executed first to transform the payload
before
middleware get executed synchronously in order- commands get executed in the order defined
- If an exception is thrown during commands, no more commands get executed and the current set of operations are not applied
after
middleware get executed synchronously in order
Multiple middlewares may get defined by providing a list. Middlewares get called synchronously in the order listed.
Before
A before
middleware block gets passed a payload
and a reference to the store
.
After
An after
middleware block gets passed an error
(if one occurred) and the of a process.
The result
implements the ProcessResult
interface to provide information about the changes applied to the store and provide access to that store.
executor
- allows additional processes to run against the storestore
- a reference to the storeoperations
- a list of applied operationsundoOperations
- a list of operations that can be used to reverse the applied operationsapply
- the apply method from the storepayload
- the provided payload
The Store
has an onChange(path, callback)
method that takes a path or an array of paths and invokes a callback function whenever that state changes.
The Store
also has an event that fires any time the store changes.