UNPKG

@nteract/epics

Version:
66 lines 3.57 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.commListenEpic = void 0; const messaging_1 = require("@nteract/messaging"); const redux_observable_1 = require("redux-observable"); const rxjs_1 = require("rxjs"); const operators_1 = require("rxjs/operators"); const actions_1 = require("@nteract/actions"); const selectors = __importStar(require("@nteract/selectors")); const types_1 = require("@nteract/types"); const ipywidgets_1 = require("./ipywidgets"); /** * An epic that emits comm actions from the backend kernel * @param {Observable} action$ Action Observable from redux-observable * @param {redux.Store} store the redux store * @return {Observable} Comm actions */ exports.commListenEpic = (action$, state$) => action$.pipe( // A LAUNCH_KERNEL_SUCCESSFUL action indicates we have a new channel redux_observable_1.ofType(actions_1.LAUNCH_KERNEL_SUCCESSFUL), operators_1.switchMap((action) => { const { payload: { kernel, contentRef } } = action; /** * We need the model of the currently loaded notebook so we can * determine what notebook to render the output of the widget onto. */ const model = selectors.model(state$.value, { contentRef }); const kernelRef = selectors.kernelRefByContentRef(state$.value, { contentRef }); // Listen on the comms channel until KILL_KERNEL_SUCCESSFUL is emitted const commOpenAction$ = kernel.channels.pipe(messaging_1.ofMessageType("comm_open"), operators_1.map(actions_1.commOpenAction), operators_1.takeUntil(action$.pipe(redux_observable_1.ofType(actions_1.KILL_KERNEL_SUCCESSFUL), operators_1.filter((action) => action.payload.kernelRef === kernelRef))), operators_1.catchError((error) => { return rxjs_1.of(actions_1.executeFailed({ error: new Error("The WebSocket connection has unexpectedly disconnected."), code: types_1.errors.EXEC_WEBSOCKET_ERROR, contentRef })); })); const commMessageAction$ = kernel.channels.pipe(messaging_1.ofMessageType("comm_msg"), operators_1.map(actions_1.commMessageAction), operators_1.takeUntil(action$.pipe(redux_observable_1.ofType(actions_1.KILL_KERNEL_SUCCESSFUL), operators_1.filter((action) => action.payload.kernelRef === kernelRef))), operators_1.catchError((error) => { return rxjs_1.of(actions_1.executeFailed({ error: new Error("The WebSocket connection has unexpectedly disconnected."), code: types_1.errors.EXEC_WEBSOCKET_ERROR, contentRef })); })); return rxjs_1.merge(ipywidgets_1.ipywidgetsModel$(kernel, model, contentRef), commOpenAction$, commMessageAction$); })); //# sourceMappingURL=comm.js.map