Options
All
  • Public
  • Public/Protected
  • All
Menu

Package selectors

@nteract/selectors

This package provides a set of selectors and functions that allow you to extract important information from the state of your nteract application. To see a full set of the data stored in application state that be extracted with this package, you can view the AppState type.

Installation

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

Usage

import { modalType, currentTheme } from "@nteract/selectors";

const state = { config: { theme: "dark" }, core: { entities: { modals: { modalType: "ABOUT" } } } };

const theme = currentTheme(state); const currentModal = modalType(state); console.log(Rendering ${currentModal} modal using ${theme} theme.); > Rendering ABOUT modal using dark theme.

Documentation

You can view the reference documentation for @nteract/selectors in the package docs.

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:selectors label.

License

BSD-3-Clause

Index

Variables

Const CODE_MIRROR_MODE_DEFAULT

CODE_MIRROR_MODE_DEFAULT: "text" = "text"

Const asJSON

asJSON: function & object = createSelector(notebook, notebook => {return commutable.toJS(notebook);})

Returns the JSON representation of the notebook.

Const asString

asString: function & object = createSelector(asJSON, notebookJS => {if (notebookJS) {return commutable.stringifyNotebook(notebookJS);}return "";})

Returns the stringified version of a notebook. Returns an empty string if no notebookJS exists. Note that this is called asString instead of toString so that REPLs don't think of this as the representation of this module.

Const codeMirrorMode

codeMirrorMode: function & object = createSelector(metadata,metadata =>metadata.getIn(["language_info", "codemirror_mode"]) ||metadata.getIn(["kernel_info", "language"]) ||metadata.getIn(["kernelspec", "language"]) ||CODE_MIRROR_MODE_DEFAULT)

Returns the CodeMirror mode of the current notebook. This value can be used to initialize the mode option in CodeMirror. Returns text if no mode is set.

Const currentHostType

currentHostType: function & object = createSelector([currentHost],host => {if (host && host.type) {return host.type;}return null;})

Returns the type of host the nteract application is currently connected to. This is set to "jupyter" by default.

Const currentKernel

currentKernel: function & object = createSelector([currentKernelRef, kernelsByRef],(kernelRef, byRef) => (kernelRef ? byRef.get(kernelRef) : null))

Returns the kernelspec of the kernel that we are currently connected to. Returns null if there is no kernel.

Const currentKernelStatus

currentKernelStatus: function & object = createSelector([currentKernel],kernel => {if (kernel && kernel.status) {return kernel.status;}return "not connected";})

Returns the state of the kernel the nteract application is currently connected to. Returns "not connected" if there is no kernel.

Const currentKernelType

currentKernelType: function & object = createSelector(currentKernel,kernel => {if (kernel && kernel.type) {return kernel.type;}return null;})

Returns the type of the kernel the nteract application is currently connected to. Returns null if there is no kernel.

Const currentTheme

currentTheme: userTheme = userTheme

Returns the theme of the notebook. Returns "light" if no theme is defined. This is an alias for the userTheme selector.

param

The state of the nteract application

returns

The theme of the nteract application

Const displayName

displayName: function & object = createSelector(metadata, metadata =>metadata.getIn(["kernelspec", "display_name"], ""))

Returns the display name of the kernel the notebook is currently running against.

Const gistId

gistId: function & object = createSelector(metadata, metadata =>metadata.get("gist_id", null))

Returns the ID of the GitHub Gist the notebook has been recently published to.

Const githubUsername

githubUsername: function & object = createSelector(metadata, metadata =>metadata.get("github_username", null))

Returns the GitHub username the user has authenticated through.

Const isCurrentHostJupyter

isCurrentHostJupyter: function & object = createSelector(currentHostType,hostType => hostType === "jupyter")

Returns true if the host we are currently connected to is a Jupyter kernel.

Const isCurrentKernelJupyterWebsocket

isCurrentKernelJupyterWebsocket: function & object = createSelector([currentHostType, currentKernelType],(hostType, kernelType) => {return hostType === "jupyter" && kernelType === "websocket";})

Returns whether or not we are currently connected to the kernel through a websocket connection.

Const isCurrentKernelZeroMQ

isCurrentKernelZeroMQ: function & object = createSelector([currentHostType, currentKernelType],(hostType, kernelType) => {return hostType === "local" && kernelType === "zeromq";})

Returns whether or not we are currently connected to the kernel through a ZeroMQ connection.

Const isDirty

isDirty: function & object = createSelector([notebook, savedNotebook],(original, disk) => !Immutable.is(original, disk))

Returns true if the notebook differs from the version saved to disk, and false otherwise.

Functions

Const appVersion

  • appVersion(state: AppState): string

Const autoSaveInterval

  • autoSaveInterval(state: AppState): number
  • Returns the auto-save interval to be used in the notebook. Returns an interval around the two minute range if one is not provided in the config.

    Parameters

    • state: AppState

    Returns number

Const cellAddress

  • cellAddress(__namedParameters: object): object

Const cellById

  • cellById(model: NotebookModel, __namedParameters: object): Record<MarkdownCellParams> & object | Record<CodeCellParams> & object | Record<RawCellParams> & object
  • Returns the cell within a notebook with a particular ID. Returns undefined if no cell with that ID is found in the model

    Parameters

    • model: NotebookModel

      The notebook model to extract the cell from

    • __namedParameters: object
      • id: string

    Returns Record<MarkdownCellParams> & object | Record<CodeCellParams> & object | Record<RawCellParams> & object

    Undefined or a cell with the given ID

Const cellFocused

Const cellFromState

  • cellFromState(state: AppState, __namedParameters: object): Record<MarkdownCellParams> & object | Record<CodeCellParams> & object | Record<RawCellParams> & object
  • Parameters

    • state: AppState
    • __namedParameters: object
      • contentRef: string
      • id: string

    Returns Record<MarkdownCellParams> & object | Record<CodeCellParams> & object | Record<RawCellParams> & object

Const cellMap

  • cellMap(model: NotebookModel): Map<string, Record<MarkdownCellParams> & object | Record<CodeCellParams> & object | Record<RawCellParams> & object>
  • Returns the cellMap within a given NotebookModel. Returns an empty Immutable.Map if no cellMap exists in the NotebookModel.

    Parameters

    • model: NotebookModel

      The notebook model to extract the cell map from

    Returns Map<string, Record<MarkdownCellParams> & object | Record<CodeCellParams> & object | Record<RawCellParams> & object>

    The cell map within the notebook or an empty map

Const cellOrder

Const cellPromptsById

  • cellPromptsById(model: NotebookModel, __namedParameters: object): List<any> | List<InputRequestMessage>

Const codeCellIds

Const codeCellIdsBelow

Const comms

  • comms(state: AppState): Record<CommsRecordProps> & object
  • Returns the Jupyter comms data for a given nteract application.

    Parameters

    • state: AppState

    Returns Record<CommsRecordProps> & object

Const content

  • content(state: AppState, __namedParameters: object): Record<NotebookContentRecordProps> & object | Record<DummyContentRecordProps> & object | Record<FileContentRecordProps> & object | Record<DirectoryContentRecordProps> & object
  • Parameters

    • state: AppState

      The state of the nteract application

    • __namedParameters: object
      • contentRef: string

    Returns Record<NotebookContentRecordProps> & object | Record<DummyContentRecordProps> & object | Record<FileContentRecordProps> & object | Record<DirectoryContentRecordProps> & object

    The ContentRecord for the given ref

Const contentByRef

  • contentByRef(state: AppState): Map<string, Record<NotebookContentRecordProps> & object | Record<DummyContentRecordProps> & object | Record<FileContentRecordProps> & object | Record<DirectoryContentRecordProps> & object>
  • Returns the contents, such as notebooks and files, that are currently accessible within the current notebook application.

    Parameters

    • state: AppState

      The state of the nteract application

    Returns Map<string, Record<NotebookContentRecordProps> & object | Record<DummyContentRecordProps> & object | Record<FileContentRecordProps> & object | Record<DirectoryContentRecordProps> & object>

    The contents in scope by the nteract application by ID

Const contentRefByFilepath

  • contentRefByFilepath(state: AppState, ownProps: object): string | undefined
  • Returns the ContentRef associated with a given filepath.

    Parameters

    • state: AppState

      The state of the nteract application

    • ownProps: object

      An object containing the filepath

      • filepath: string

    Returns string | undefined

    The ContentRef for the content under a filepath

Const currentHost

  • currentHost(state: AppState): Record<BaseHostProps & object> & object | Record<BaseHostProps & object> & object | Record<EmptyHost> & object
  • Returns the host the nteract application is connected to.

    Parameters

    • state: AppState

    Returns Record<BaseHostProps & object> & object | Record<BaseHostProps & object> & object | Record<EmptyHost> & object

Const currentKernelRef

  • currentKernelRef(state: AppState): string
  • Returns the KernelRef for the kernel the nteract application is currently connected to.

    Parameters

    • state: AppState

      The state of the nteract application

    Returns string

    The KernelRef for the kernel

Const currentKernelspecs

  • currentKernelspecs(state: AppState): Record<KernelspecsByRefRecordProps> & object
  • Returns the kernelspec of the kernel that the nteract application is currently connected to.

    Parameters

    • state: AppState

    Returns Record<KernelspecsByRefRecordProps> & object

Const currentKernelspecsRef

  • currentKernelspecsRef(state: AppState): string
  • Returns a ref to the kernelspec of the kernel the nteract application is currently connected to.

    Parameters

    • state: AppState

      The state of the nteract application

    Returns string

    A ref to the kernelspec

Const deleteDelay

  • deleteDelay(state: AppState): number

Const displayOrder

  • displayOrder(state: AppState): any

Const editorFocusedId

Const filepath

  • filepath(state: AppState, ownProps: object): string | null
  • Returns the filepath for the content identified by a given ContentRef.

    Parameters

    • state: AppState

      The state of the nteract application

    • ownProps: object

      An object containing the ContentRef

    Returns string | null

    The filepath for the content

Const hiddenCellIds

Const hostRecordByHostRef

  • hostRecordByHostRef(state: AppState, __namedParameters: object): Record<BaseHostProps & object> & object | Record<BaseHostProps & object> & object | Record<EmptyHost> & object
  • Returns the HostRecord associated with a hostRef.

    const hostRef = "someHostRef";
    const hostRecord = selectors.hostRecordByHostRef(state, { hostRef });

    Parameters

    • state: AppState

      The current application sate

    • __namedParameters: object
      • hostRef: string

    Returns Record<BaseHostProps & object> & object | Record<BaseHostProps & object> & object | Record<EmptyHost> & object

Const hostRefByHostRecord

  • hostRefByHostRecord(state: AppState, __namedParameters: object): string
  • Returns the HostRef associated with a HostRecord.

    const host = makeJupyterHostRecord({ endpoint: "https://example.com "});
    const ref = selectors.hostRefByHostRecord(state, { host });

    Parameters

    • state: AppState

      The current application state

    • __namedParameters: object
      • host: Record<BaseHostProps & object> & object

    Returns string

Const hostsByRef

  • hostsByRef(state: AppState): Map<string, Record<BaseHostProps & object> & object | Record<BaseHostProps & object> & object | Record<EmptyHost> & object>
  • Returns the hosts currently registered on the application by their refs.

    Parameters

    • state: AppState

      The crrent application state

    Returns Map<string, Record<BaseHostProps & object> & object | Record<BaseHostProps & object> & object | Record<EmptyHost> & object>

Const idsOfHiddenOutputs

Const info

  • info(state: AppState): Map<any, any>

Const infoById

  • infoById(state: AppState, __namedParameters: object): any
  • Returns the information associated with a comm registered at a certain id.

    Parameters

    • state: AppState

      The current application state

    • __namedParameters: object
      • commId: string

    Returns any

Const kernel

  • kernel(state: AppState, __namedParameters: object): any
  • Returns the kernel associated with a given KernelRef.

    Parameters

    • state: AppState

      The state of the nteract application

    • __namedParameters: object
      • kernelRef: string

    Returns any

    The kernel for the KernelRef

Const kernelByContentRef

  • kernelByContentRef(state: AppState, ownProps: object): Record<KernelNotStartedProps> & object | Record<LocalKernelProps> & object | Record<RemoteKernelProps> & object

Const kernelRefByContentRef

  • kernelRefByContentRef(state: AppState, ownProps: object): KernelRef | null | undefined
  • Returns a ref to the kernel associated with a particular type of content. Currently, this only support kernels associated with notebook contents. Returns null if there are no contents or if the contents are not a notebook.

    Parameters

    • state: AppState

      The state of the nteract application

    • ownProps: object

    Returns KernelRef | null | undefined

    The kernel associated with a notebook

Const kernelsByRef

  • kernelsByRef(state: AppState): Map<string, Record<KernelNotStartedProps> & object | Record<LocalKernelProps> & object | Record<RemoteKernelProps> & object>
  • Returns a map of the available kernels keyed by the kernel ref.

    Parameters

    • state: AppState

      The state of the nteract application

    Returns Map<string, Record<KernelNotStartedProps> & object | Record<LocalKernelProps> & object | Record<RemoteKernelProps> & object>

    The kernels by ref

Const kernelspecByName

  • kernelspecByName(state: AppState, __namedParameters: object): Record<KernelspecProps> & object

Const kernelspecsByRef

  • kernelspecsByRef(state: AppState): Map<string, Record<KernelspecsByRefRecordProps> & object>
  • Returns a Map of the kernelspecs associated with each kernelspec ref.

    Parameters

    • state: AppState

      The state of the nteract application

    Returns Map<string, Record<KernelspecsByRefRecordProps> & object>

    An association between a kernelspec ref and the kernelspec

Const metadata

Const modalType

  • modalType(state: AppState): string
  • Returns the type of modal, such as the about modal, that is currently open in the nteract application.

    Parameters

    • state: AppState

    Returns string

Const model

  • model(state: AppState, __namedParameters: object): Record<DocumentRecordProps> & object | Record<EmptyModelRecordProps> & object | Record<FileModelRecordProps> & object | Record<DirectoryModelRecordProps> & object
  • Returns the model within the ContenteRecrd specified by contentRef. For example, if the ContentRecord is a reference to a notebook object, the model would contain the NotebookModel.

    Parameters

    • state: AppState

      The state of the nteract application

    • __namedParameters: object
      • contentRef: string

    Returns Record<DocumentRecordProps> & object | Record<EmptyModelRecordProps> & object | Record<FileModelRecordProps> & object | Record<DirectoryModelRecordProps> & object

    The model of the content under the current ref

Const modelById

  • modelById(state: AppState, __namedParameters: object): any
  • Returns the model associated with a comm at a certain id.

    Parameters

    • state: AppState

      The current application state

    • __namedParameters: object
      • commId: string

    Returns any

Const models

  • models(state: AppState): Map<any, any>
  • Returns the comms models that are stored in the nteract application state.

    Parameters

    • state: AppState

    Returns Map<any, any>

Const notebook

  • notebook(model: NotebookModel): Record<NotebookRecordParams> & object

Const notificationSystem

  • notificationSystem(state: AppState): object
  • Returns the notification system currently configured on the nteract application. This can be used to display informational or error-related alerts to the user.

    Parameters

    • state: AppState

    Returns object

    • addNotification: function
        • (msg: Notification): void
        • Parameters

          • msg: Notification

          Returns void

Const savedNotebook

  • savedNotebook(model: NotebookModel): Record<NotebookRecordParams> & object

Const serverConfig

Const targetById

  • targetById(state: AppState, __namedParameters: object): any
  • Returns the handler associated with a comm target at a certain id.

    Parameters

    • state: AppState

      The current application state

    • __namedParameters: object
      • commId: string

    Returns any

Const targets

  • targets(state: AppState): Map<any, any>
  • Returns the registered comm targets that are stored in the nteract application state.

    Parameters

    • state: AppState

    Returns Map<any, any>

Const transform

  • transform(state: AppState, __namedParameters: object): any

Const transformsById

  • transformsById(state: AppState): any

Const transientCellMap

Const userTheme

  • userTheme(state: AppState): string
  • Returns the theme of the notebook. Returns "light" if no theme is defined.

    Parameters

    • state: AppState

      The state of the nteract application

    Returns string

    The theme of the nteract application

Generated using TypeDoc