Abstract
The extending Store InstanceType.
Well-known Symbol.observable
method returning a Subscribable. The
returned Subscribable emits all States this Store
traverses, i.e., all States that result from dispatching
Actions on this Store.
A Subscribable emitting State changes.
An ReferenceError when not called Stateful.
Subscribe to the ExampleStore
:
import { ExampleStore } from './example-store';
const store = new ExampleStore();
from(store).subscribe(console.log);
The dispatch method provides a facade to dispatch an Action through the StateHandler when this Store was decorated with the Stateful decorator, otherwise calling this method will throw an ReferenceError.
An Observable of the resulting State.
An ReferenceError when not called Stateful.
Dispatch an Action to the ExampleStore
:
import { ExampleStore } from './example-store';
const store = new ExampleStore();
store.dispatch('action', ['value']).subscribe();
Generated using TypeDoc
Abstract Store base class. By extending this Store base class and decorating the extending class with the Stateful decorator, the resulting Store will become a functional facade implementing only the dispatch and well-known
Symbol.observable
methods. This resulting facade provides convenient access to the current and upcoming States of the Store and its dispatch method, while, behind the facade, interactions with the BusHandler to provide an Observable of the State changes and the StateHandler to dispatch any Actions will be handled transparently.The same functionality can be achieved by manually supplying a Store to the StateHandler and subscribing to the changes of that Store through the BusHandler while any Actions also have to be passed manually to the StateHandler. But the Stateful decorator should be preferred out of convenience and because invoking the constructor of the Store class throws a TypeError.
Example
A simple
ExampleStore
facade:Example
Subscribe to the
ExampleStore
facade:Example
Dispatch an Action through the
ExampleStore
facade: