Options
All
  • Public
  • Public/Protected
  • All
Menu

Package epics

@nteract/epics

This package contains a set of Redux-Observable epics for use in nteract applications.

Installation

$ yarn add @nteract/epics
$ npm install --save @nteract/epics

Usage

The example below shows how we can use the watchExecutionStateEpic to monitor the state of a recently launched kernel.

import { watchExecutionStateEpic } from "@nteract/epics";

export default () => { // Create a Observable for the successful launch of a // kernel. const action$ = ActionsObservable.of({ type: actionTypes.LAUNCH_KERNEL_SUCCESSFUL, payload: { kernel: { channels: of({ header: { msg_type: "status" }, content: { execution_state: "idle" } }) } } }); // Monitor the Observable and update the // state of the kernel on our client appropriately. const obs = watchExecutionStateEpic(action$); obs.pipe(toArray()).subscribe( actions => { const types = actions.map(({ type }) => type); expect(types).toEqual([actionTypes.SET_EXECUTION_STATE]); }, err => done.fail(err), // It should not error in the stream () => done() ); }); }

Documentation

We're working on adding more documentation for this component. Stay tuned by watching this repository!

Support

If you experience an issue while using this package or have a feature request, please file an issue on the issue board and add the pkg:epics label.

License

BSD-3-Clause

Index

Variables

Const Immutable

Immutable: any = require("immutable")

Const allEpics

allEpics: (executeCellEpic | executeAllCellsEpic | launchWebSocketKernelEpic | changeWebSocketKernelEpic | interruptKernelEpic | killKernelEpic | acquireKernelInfoEpic | fetchKernelspecsEpic | fetchContentEpic | updateContentEpic | saveContentEpic | publishToBookstore | publishToBookstoreAfterSave | restartWebSocketKernelEpic | closeNotebookEpic)[] = [executeCellEpic,updateDisplayEpic,executeAllCellsEpic,commListenEpic,launchWebSocketKernelEpic,changeWebSocketKernelEpic,interruptKernelEpic,killKernelEpic,acquireKernelInfoEpic,watchExecutionStateEpic,launchKernelWhenNotebookSetEpic,restartKernelEpic,fetchKernelspecsEpic,fetchContentEpic,updateContentEpic,saveContentEpic,autoSaveCurrentContentEpic,publishToBookstore,publishToBookstoreAfterSave,restartWebSocketKernelEpic,sendInputReplyEpic,closeNotebookEpic]

Const path

path: any = require("path")

Functions

acquireKernelInfo

Const acquireKernelInfoEpic

  • acquireKernelInfoEpic(action$: ActionsObservable<NewKernelAction>, state$: StateObservable<AppState>): Observable<unknown>
  • Gets information about newly launched kernel.

    Parameters

    • action$: ActionsObservable<NewKernelAction>
    • state$: StateObservable<AppState>

    Returns Observable<unknown>

autoSaveCurrentContentEpic

  • autoSaveCurrentContentEpic(action$: ActionsObservable<Action>, state$: StateObservable<AppState>): Observable<Save>

Const changeWebSocketKernelEpic

  • changeWebSocketKernelEpic(action$: ActionsObservable<ChangeKernelByName>, state$: StateObservable<AppState>): Observable<NewKernelAction | LaunchKernelFailed>

closeNotebookEpic

  • closeNotebookEpic(action$: ActionsObservable<CloseNotebook>, state$: StateObservable<AppState>): Observable<DisposeContent | KillKernelAction>
  • Parameters

    • action$: ActionsObservable<CloseNotebook>
    • state$: StateObservable<AppState>

    Returns Observable<DisposeContent | KillKernelAction>

Const commListenEpic

  • commListenEpic(action$: ActionsObservable<NewKernelAction | KillKernelSuccessful>, state$: StateObservable<AppState>): Observable<object | AppendOutput | object>
  • An epic that emits comm actions from the backend kernel

    Parameters

    • action$: ActionsObservable<NewKernelAction | KillKernelSuccessful>

      Action Observable from redux-observable

    • state$: StateObservable<AppState>

    Returns Observable<object | AppendOutput | object>

    Comm actions

convertNotebookToContent

  • convertNotebookToContent(content: NotebookContentRecordProps): Partial<IContent<"notebook">> & object
  • Converts a Notebook content to the Jupyter Content type expected in Bookstore.

    Parameters

    • content: NotebookContentRecordProps

      Notebook

    Returns Partial<IContent<"notebook">> & object

createExecuteCellStream

  • createExecuteCellStream(action$: ActionsObservable<ExecuteCanceled | DeleteCell | LaunchKernelAction | LaunchKernelByNameAction | KillKernelAction | ExecuteCell | ExecuteFocusedCell>, state: any, message: ExecuteRequest, id: string, contentRef: ContentRef): Observable<any>
  • Parameters

    • action$: ActionsObservable<ExecuteCanceled | DeleteCell | LaunchKernelAction | LaunchKernelByNameAction | KillKernelAction | ExecuteCell | ExecuteFocusedCell>
    • state: any
    • message: ExecuteRequest
    • id: string
    • contentRef: ContentRef

    Returns Observable<any>

downloadString

  • downloadString(fileContents: string, filepath: string, contentType: string): void

executeAllCellsEpic

  • executeAllCellsEpic(action$: ActionsObservable<ExecuteAllCells | ExecuteAllCellsBelow>, state$: StateObservable<AppState>): Observable<any>
  • Parameters

    • action$: ActionsObservable<ExecuteAllCells | ExecuteAllCellsBelow>
    • state$: StateObservable<AppState>

    Returns Observable<any>

executeCellEpic

  • executeCellEpic(action$: ActionsObservable<ExecuteCell | ExecuteFocusedCell>, state$: any): Observable<any>
  • the execute cell epic processes execute requests for all cells, creating inner observable streams of the running execution responses

    Parameters

    • action$: ActionsObservable<ExecuteCell | ExecuteFocusedCell>
    • state$: any

    Returns Observable<any>

executeCellStream

  • Observe all the reactions to running code for cell with id.

    Parameters

    • channels: Channels

      The standard channels specified in the Jupyter specification.

    • id: string

      Universally Unique Identifier of cell to be executed.

    • message: ExecuteRequest
    • contentRef: ContentRef

    Returns any

    updatedOutputs - It returns an observable with a stream of events that need to happen after a cell has been executed.

Const extractNewKernel

fetchContentEpic

  • fetchContentEpic(action$: ActionsObservable<FetchContent | FetchContentFailed | FetchContentFulfilled>, state$: StateObservable<AppState>): Observable<unknown>
  • Parameters

    • action$: ActionsObservable<FetchContent | FetchContentFailed | FetchContentFulfilled>
    • state$: StateObservable<AppState>

    Returns Observable<unknown>

Const fetchKernelspecsEpic

  • fetchKernelspecsEpic(action$: ActionsObservable<FetchKernelspecs>, state$: any): Observable<FetchKernelspecsFulfilled | FetchKernelspecsFailed>
  • Parameters

    • action$: ActionsObservable<FetchKernelspecs>
    • state$: any

    Returns Observable<FetchKernelspecsFulfilled | FetchKernelspecsFailed>

Const interruptKernelEpic

  • interruptKernelEpic(action$: ActionsObservable<InterruptKernel>, state$: StateObservable<AppState>): Observable<InterruptKernelFailed | InterruptKernelSuccessful>
  • Parameters

    • action$: ActionsObservable<InterruptKernel>
    • state$: StateObservable<AppState>

    Returns Observable<InterruptKernelFailed | InterruptKernelSuccessful>

Const ipywidgetsModel$

  • ipywidgetsModel$(kernel: LocalKernelProps | RemoteKernelProps, model: RecordOf<DocumentRecordProps> | RecordOf<EmptyModelRecordProps> | RecordOf<FileModelRecordProps> | RecordOf<DirectoryModelRecordProps> | null, contentRef: ContentRef): Observable<object | AppendOutput>
  • Listen for comm_open messages from the kernel that are associated with models that will not be rendered on the page.

    Note: this is not an ideal solution but we need to do this so that we can keep the WidgetManager contextualized to the WidgetDisplay as opposed to at the top-level.

    Parameters

    • kernel: LocalKernelProps | RemoteKernelProps
    • model: RecordOf<DocumentRecordProps> | RecordOf<EmptyModelRecordProps> | RecordOf<FileModelRecordProps> | RecordOf<DirectoryModelRecordProps> | null
    • contentRef: ContentRef

    Returns Observable<object | AppendOutput>

Const killKernelEpic

  • killKernelEpic(action$: ActionsObservable<KillKernelAction>, state$: StateObservable<AppState>): Observable<KillKernelSuccessful | KillKernelFailed | DisposeKernel>
  • Parameters

    • action$: ActionsObservable<KillKernelAction>
    • state$: StateObservable<AppState>

    Returns Observable<KillKernelSuccessful | KillKernelFailed | DisposeKernel>

Const launchKernelWhenNotebookSetEpic

  • launchKernelWhenNotebookSetEpic(action$: ActionsObservable<FetchContentFulfilled>, state$: any): Observable<LaunchKernelByNameAction>
  • NOTE: This function is exactly the same as the desktop loading.js version with one strong exception -- extractNewKernel Can they be combined without incurring a penalty on the web app? The native functions used are path.dirname, path.resolve, and process.cwd() We could always inject those dependencies separately...

    Parameters

    • action$: ActionsObservable<FetchContentFulfilled>
    • state$: any

    Returns Observable<LaunchKernelByNameAction>

Const launchWebSocketKernelEpic

  • launchWebSocketKernelEpic(action$: ActionsObservable<LaunchKernelByNameAction>, state$: StateObservable<AppState>): Observable<NewKernelAction | LaunchKernelFailed>
  • Parameters

    • action$: ActionsObservable<LaunchKernelByNameAction>
    • state$: StateObservable<AppState>

    Returns Observable<NewKernelAction | LaunchKernelFailed>

publishToBookstore

  • publishToBookstore(action$: ActionsObservable<PublishToBookstore>, state$: StateObservable<AppState>): Observable<unknown>
  • First step in publishing notebooks to bookstore. Saves notebook using the content API. Then, kicks off an action that saves the notebook to Bookstore.

    Parameters

    • action$: ActionsObservable<PublishToBookstore>

      Action type.

    • state$: StateObservable<AppState>

      Application state.

    Returns Observable<unknown>

publishToBookstoreAfterSave

  • publishToBookstoreAfterSave(action$: ActionsObservable<PublishToBookstoreAfterSave>, state$: StateObservable<AppState>): Observable<void | PublishToBookstoreFailed>
  • Last step in publishing notebooks to bookstore. Saves notebook to Bookstore.

    Parameters

    • action$: ActionsObservable<PublishToBookstoreAfterSave>

      Action type.

    • state$: StateObservable<AppState>

      Application state.

    Returns Observable<void | PublishToBookstoreFailed>

Const restartKernelEpic

  • restartKernelEpic(action$: ActionsObservable<RestartKernel | NewKernelAction>, state$: any, kernelRefGenerator?: function): Observable<KillKernelAction | LaunchKernelByNameAction | ExecuteAllCells | RestartKernelSuccessful | RestartKernelFailed>
  • Restarts a Jupyter kernel in the local scenario, where a restart requires killing the existing kernel process and starting an ew one.

    Parameters

    • action$: ActionsObservable<RestartKernel | NewKernelAction>
    • state$: any
    • Default value kernelRefGenerator: function = createKernelRef

    Returns Observable<KillKernelAction | LaunchKernelByNameAction | ExecuteAllCells | RestartKernelSuccessful | RestartKernelFailed>

Const restartWebSocketKernelEpic

  • restartWebSocketKernelEpic(action$: ActionsObservable<RestartKernel>, state$: StateObservable<AppState>): Observable<ExecuteAllCells | RestartKernelSuccessful | RestartKernelFailed | ClearAllOutputs>
  • Parameters

    • action$: ActionsObservable<RestartKernel>
    • state$: StateObservable<AppState>

    Returns Observable<ExecuteAllCells | RestartKernelSuccessful | RestartKernelFailed | ClearAllOutputs>

saveAsContentEpic

  • saveAsContentEpic(action$: ActionsObservable<SaveAs>, state$: StateObservable<AppState>): Observable<SaveAsFailed | SaveAsFulfilled>
  • Parameters

    • action$: ActionsObservable<SaveAs>
    • state$: StateObservable<AppState>

    Returns Observable<SaveAsFailed | SaveAsFulfilled>

saveContentEpic

  • saveContentEpic(action$: ActionsObservable<Save | DownloadContent>, state$: StateObservable<AppState>): Observable<DownloadContentFailed | DownloadContentFulfilled | SaveFailed | SaveFulfilled>
  • Parameters

    • action$: ActionsObservable<Save | DownloadContent>
    • state$: StateObservable<AppState>

    Returns Observable<DownloadContentFailed | DownloadContentFulfilled | SaveFailed | SaveFulfilled>

Const sendInputReplyEpic

  • sendInputReplyEpic(action$: ActionsObservable<SendInputReply>, state$: StateObservable<AppState>): Observable<never>

serializeContent

  • serializeContent(state: AppState, content: RecordOf<NotebookContentRecordProps> | RecordOf<DummyContentRecordProps> | RecordOf<FileContentRecordProps> | RecordOf<DirectoryContentRecordProps>): object
  • Parameters

    • state: AppState
    • content: RecordOf<NotebookContentRecordProps> | RecordOf<DummyContentRecordProps> | RecordOf<FileContentRecordProps> | RecordOf<DirectoryContentRecordProps>

    Returns object

    • saveModel: object
    • serializedData: string | NotebookV4

updateContentEpic

  • updateContentEpic(action$: ActionsObservable<ChangeContentName>, state$: StateObservable<AppState>): Observable<unknown>
  • Parameters

    • action$: ActionsObservable<ChangeContentName>
    • state$: StateObservable<AppState>

    Returns Observable<unknown>

Const updateDisplayEpic

  • updateDisplayEpic(action$: ActionsObservable<NewKernelAction | KillKernelSuccessful>): Observable<UpdateDisplay | UpdateDisplayFailed>
  • Parameters

    • action$: ActionsObservable<NewKernelAction | KillKernelSuccessful>

    Returns Observable<UpdateDisplay | UpdateDisplayFailed>

Const watchExecutionStateEpic

  • watchExecutionStateEpic(action$: ActionsObservable<NewKernelAction | KillKernelSuccessful>): Observable<SetExecutionStateAction>
  • Sets the execution state after a kernel has been launched.

    Parameters

    • action$: ActionsObservable<NewKernelAction | KillKernelSuccessful>

    Returns Observable<SetExecutionStateAction>

Generated using TypeDoc