MilesB
MilesB

Reputation: 96

RXJS + Redux Observable - how to merge a new stream?

We've recently picked up Redux Observable and it's been a great way to manage high level action orchestration.

One problem I've recently is responding to the result of a data fetch. We have a generic service function which returns a RXJS observable. Normally we select what ever data we need and subscribe.

I thought this would be fairly natural with redux-observable. Use MapTo on the Epic, and return the RXJS observer with the subsequent select.

From what I can tell Redux-observable doesn't subscribe so nothing happens.

Does anyone have an example of how it should work?

export function redirectUserToEndpointEpic(action$) { return action$.ofType(LOCATION_CHANGE) .filter(action=>action.payload.pathname !== '/')) .mapTo(action=>authService.getObserver() // returns a stream which has not been subscribed to .select(userData=>userData.defaultPath) .map(push); }

Upvotes: 1

Views: 408

Answers (1)

MilesB
MilesB

Reputation: 96

This code is actually correct. The dependency was using 'rx' library rather than 'rxjs' which caused a conflict.

Thanks all

Upvotes: 0

Related Questions