store icon indicating copy to clipboard operation
store copied to clipboard

Request for articles/epics.md

Open westandy-dcp opened this issue 6 years ago • 2 comments

This is a...

  • feature request

I would like the Epics.md updated to reflect some modern approaches to the login epic. The following example is how we implemented an epic. The main part that bothered me with your current example is the embedded http.post(...).pipe(...) because it reminds me too much of the old callback hell.

For what it is worth, I hope this helps some folks develop cleaner code.

  login = (action$: ActionsObservable) =>
     action$.pipe(
       ofType(SessionActions.LOGIN_USER),
       map(() => getSomePayload()),
       map((payload: SomeStruct) => formatPayload(payload)),
       mergeMap((payload: SomeOtherStruct) => this.http.post(...)),
       map(response:any) => Actions.createAnAction(response)),
       catchError(this.handleError)
    )

westandy-dcp avatar Feb 14 '19 22:02 westandy-dcp

Also, there seems to be a problem with the current version of ActionsObservable. I keep getting this error:

Generic type 'ActionsObservable<T>' requires 1 type argument(s).ts(2314)

I'm using "redux-observable": "^1.1.0"

takahser avatar Sep 09 '19 11:09 takahser

I was able to resolve this issue by replacing the redux-observable dependency with

"redux-observable-es6-compat": "^1.2.1",

related: https://github.com/redux-observable/redux-observable/issues/644

takahser avatar Sep 12 '19 09:09 takahser