-
-
Save rostero1/94b86bb1b154ae4b2211f2e00e4b0e0a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createMachineEpic(machine, _, updateStoreActionFn) { | |
return function epic(action$) { | |
const service = interpret(machine); | |
const state$ = fromEventPattern( | |
handler => { | |
service.onTransition(handler).start(); | |
return service; | |
}, | |
(_, service) => service.stop() | |
).pipe(map(([state, action]) => updateStoreActionFn(state, action))); | |
return merge( | |
state$, | |
action$.pipe( | |
filter(({ type }) => machine.handles(type)), | |
tap(action => { | |
service.send(action); | |
}), | |
ignoreElements() | |
) | |
); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment