0
votes

answering my own question:

it makes sense that the epic (at the end) should return a stream of its own

but what about the chained function calls in between? Can I return plan objects and then return a stream at the end?

do I need to return the observable itself or the subscription object?

for example:

is this idiomatic "rxjs" or redux-observable?

const epic = ($action, store) =>
    action$
        .filter(filterFunction)
        .map(action => processAction(action, store))
        .map(processResult)
        .flatMap(apiCall)
        .map(res => ({ type: 'DONE', payload: res }))


const processAction = (action, store) =>
    Observable.create(
        obs => {
            const result = // do something with store and action

            return obs.next(result)
        })

const processResult = result =>
    result.subscribe(res => {
        const newRes = // do some other stuff
        return Observable.from({ newRes })
    })

epic: takes actionStream, filters for X type, maps each type to a diff operation, packages and sends request body to server, informs reducer that server call was successful

processAction: receives actions of X type, map each action to a process that compares snapshots (from the store) and outputs the cumulative DIFF between state trees.

processResult: receives DIFF and creates payload request body

1

1 Answers

3
votes

That would not be idiomatic rxjs because map is supposed to be side effect free; in your example it's being abused quite heavily. I don't believe it entirely does what you intend.

I'm happy to suggest some patterns if you want to describe what you'd like to do :)