-
Notifications
You must be signed in to change notification settings - Fork 7
Actions
Timo Dörr edited this page Aug 22, 2018
·
6 revisions
In reactive-state, any observable can be an action. The items emitted by the observable will be picked up by the reducer that is registered together with an action via the .addReducer()
function on the store. Subject
s make perfect actions as well:
const subjectAction = new Subject<number>();
const customAction = new Observable<P>(observer => { /* ... */});
const timerAction = interval(1000);
An action is dispatched, whenever the Observable emits a value. When using a Subject
, just call the .next()
function and pass the payload as argument:
subjectAction.next(10);
Dispatching an action will not change the state, if there are no reducers assigned for that action. See the Section on the .addReducer
function in Store and Reducers for more info.