emce-async
v0.9.6
Published
Async handling for Emce
Downloads
2
Readme
Emce Async
A mixin for Emce to handle observables of actions.
Installation
Install from npm:
npm install emce-async --save
or
yarn add emce-async
Asynchronous actions
When you have to handle something asynchronous just send in an observable of actions to next
. It should never error so if you are mapping from another observable, make sure you catch any errors. It will execute all actions that are sent until completed. Make sure you send a complete so that the observable can be cleaned up correctly.
emce.next(httpLib.get('example')
.map(responseToAction)
.catch(errorToAction));
Middleware
Each action in the observable will go through the normal action flow and will be passed through any middleware used.
const actions: Observable<ExampleAction> = httpLib.get('example')
.map(responseToAction())
.catch(errorToAction());
emce.next(actions$);
Triggering Asynchronous actions
Just add a function called triggerAsync
on the `handlers. Then you can trigger an observable as a response to an action, in a similar way to triggering actions. This will also trigger for actions on the emce you registered the trigger on, not just on children. Any observable created will be subscribed to after the action that triggered it has completed. This means that the action has completed fully, i.e. the updates have bubbled up to the root emce, and all children have been given an updated model.
triggerAsync: (model: T | null, action: A extends Action) => Observable<A> | null;
A function that might return an observable of actions in response to a model and an action.