Skip to content

Instantly share code, notes, and snippets.

@captainsafia
Last active January 15, 2020 03:25
Show Gist options
  • Save captainsafia/050bd3b774c926c5178d318ddf5b1025 to your computer and use it in GitHub Desktop.
Save captainsafia/050bd3b774c926c5178d318ddf5b1025 to your computer and use it in GitHub Desktop.
/** 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