Last active
January 15, 2020 03:25
-
-
Save captainsafia/050bd3b774c926c5178d318ddf5b1025 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
/** Launch a new kernel when the app host token changes. **/ | |
const launchKernelWhenTokenChanged = (action$, state$) => | |
// Whenever a new kernel is launched we execute this logic | |
action$.pipe(ofType("LAUNCH_KERNEL_SUCCESSFUL"), | |
switchMap((action) => | |
// We subscribe to the StateObservable, which is a stream of changes to the Redux state | |
state$.pipe( | |
// We pull out the property we care about, the token field in the core state | |
pluck("app", "host", "token"), | |
// We only move on to the next step if it has changed https://www.learnrxjs.io/operators/filtering/distinctuntilchanged.html | |
distinctUntilChanged(), | |
// if so we launch a kernel by name | |
concatMap(() => of(actions.launchKernelByName({ contentRef: action.payload.contentRef, .... }) | |
))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment