Skip to content
Timo Dörr edited this page Aug 22, 2018 · 6 revisions

Creating Actions

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. Subjects make perfect actions as well:

const subjectAction = new Subject<number>();
const customAction = new Observable<P>(observer => { /* ... */});
const timerAction = interval(1000);

Dispatching actions

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.