UNPKG

@nteract/epics

Version:
71 lines 3.38 kB
"use strict"; /** * This file contains epics associated with processing * particular types of messages returned from and sent to * the Jupyter kernel. */ 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.sendInputReplyEpic = exports.updateDisplayEpic = void 0; const redux_observable_1 = require("redux-observable"); const rxjs_1 = require("rxjs"); const operators_1 = require("rxjs/operators"); const actions = __importStar(require("@nteract/actions")); const messaging_1 = require("@nteract/messaging"); const selectors = __importStar(require("@nteract/selectors")); /** * Process update_display_data messages that are sent from a Jupyter * kernel. This logic is placed in its own epic, as opposed to the core * execution epics because the kernel can send update_display_data messages * at any time. * * @param action$ The stream of actions being dispatched on the Redux store */ exports.updateDisplayEpic = (action$) => // Global message watcher so we need to set up a feed for each new kernel action$.pipe(redux_observable_1.ofType(actions.LAUNCH_KERNEL_SUCCESSFUL), operators_1.switchMap((action) => action.payload.kernel.channels.pipe(messaging_1.ofMessageType("update_display_data"), operators_1.map((msg) => actions.updateDisplay({ content: msg.content, contentRef: action.payload.contentRef })), operators_1.takeUntil(action$.pipe(redux_observable_1.ofType(actions.KILL_KERNEL_SUCCESSFUL), operators_1.filter((killAction) => killAction.payload.kernelRef === action.payload.kernelRef))), operators_1.catchError((error) => rxjs_1.of(actions.updateDisplayFailed({ error, contentRef: action.payload .contentRef })))))); /** * Send responsese to stdin_requests to the kernel. This epic will * typically be triggered when the user executes an `input()` function * (in Python) then provides a response on the resulting form. * * @param action$ The stream of actions dispatched to the Redux store * @param state$ The stream of changes to the Redux store */ exports.sendInputReplyEpic = (action$, state$) => action$.pipe(redux_observable_1.ofType(actions.SEND_INPUT_REPLY), operators_1.switchMap((action) => { const state = state$.value; const kernel = selectors.kernelByContentRef(state, { contentRef: action.payload.contentRef }); if (kernel) { const reply = messaging_1.inputReply({ value: action.payload.value }); kernel.channels.next(reply); } return rxjs_1.EMPTY; })); //# sourceMappingURL=process-msgs.js.map