當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript ActionsObservable.pipe方法代碼示例

本文整理匯總了TypeScript中redux-observable.ActionsObservable.pipe方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript ActionsObservable.pipe方法的具體用法?TypeScript ActionsObservable.pipe怎麽用?TypeScript ActionsObservable.pipe使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在redux-observable.ActionsObservable的用法示例。


在下文中一共展示了ActionsObservable.pipe方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: ofType

export const updateDisplayEpic = (
  action$: ActionsObservable<NewKernelAction>
) =>
  // Global message watcher so we need to set up a feed for each new kernel
  action$.pipe(
    ofType(actions.LAUNCH_KERNEL_SUCCESSFUL),
    switchMap((action: NewKernelAction) =>
      action.payload.kernel.channels.pipe(
        ofMessageType("update_display_data"),
        map((msg: JupyterMessage) =>
          actions.updateDisplay({
            content: msg.content,
            contentRef: action.payload.contentRef
          })
        ),
        catchError(error =>
          of(
            actions.updateDisplayFailed({
              error,
              contentRef: action.payload.contentRef
            })
          )
        )
      )
    )
  );
開發者ID:kelleyblackmore,項目名稱:nteract,代碼行數:26,代碼來源:execute.ts

示例2: executeAllCellsEpic

export function executeAllCellsEpic(
  action$: ActionsObservable<ExecuteAllCells | ExecuteAllCellsBelow>,
  state$: StateObservable<AppState>
) {
  return action$.pipe(
    ofType(actions.EXECUTE_ALL_CELLS, actions.EXECUTE_ALL_CELLS_BELOW),
    concatMap((action: ExecuteAllCells | ExecuteAllCellsBelow) => {
      const state = state$.value;
      const contentRef = action.payload.contentRef;

      const model = selectors.model(state, { contentRef });
      // If it's not a notebook, we shouldn't be here
      if (!model || model.type !== "notebook") {
        return empty();
      }

      let codeCellIds = Immutable.List();

      if (action.type === actions.EXECUTE_ALL_CELLS) {
        codeCellIds = selectors.notebook.codeCellIds(model);
      } else if (action.type === actions.EXECUTE_ALL_CELLS_BELOW) {
        codeCellIds = selectors.notebook.codeCellIdsBelow(model);
      }
      return of(
        ...codeCellIds.map((id: CellId) =>
          actions.executeCell({ id, contentRef: action.payload.contentRef })
        )
      );
    })
  );
}
開發者ID:kelleyblackmore,項目名稱:nteract,代碼行數:31,代碼來源:execute.ts

示例3: ofType

export const interruptKernelEpic = (
  action$: ActionsObservable<actions.InterruptKernel>,
  state$: StateObservable<AppState>
) =>
  action$.pipe(
    ofType(actions.INTERRUPT_KERNEL),
    // This epic can only interrupt kernels on jupyter websockets
    filter(() => selectors.isCurrentHostJupyter(state$.value)),
    // If the user fires off _more_ interrupts, we shouldn't interrupt the in-flight
    // interrupt, instead doing it after the last one happens
    concatMap((action: actions.InterruptKernel) => {
      const state = state$.value;

      const host = selectors.currentHost(state);
      if (host.type !== "jupyter") {
        // Dismiss any usage that isn't targeting a jupyter server
        return empty();
      }
      const serverConfig: ServerConfig = selectors.serverConfig(host);

      const kernel = selectors.currentKernel(state);
      if (!kernel) {
        return of(
          actions.interruptKernelFailed({
            error: new Error("Can't interrupt a kernel we don't have"),
            kernelRef: action.payload.kernelRef
          })
        );
      }

      if (kernel.type !== "websocket" || !kernel.id) {
        return of(
          actions.interruptKernelFailed({
            error: new Error("Invalid kernel type for interrupting"),
            kernelRef: action.payload.kernelRef
          })
        );
      }

      const id = kernel.id;

      return kernels.interrupt(serverConfig, id).pipe(
        map(() =>
          actions.interruptKernelSuccessful({
            kernelRef: action.payload.kernelRef
          })
        ),
        catchError(err =>
          of(
            actions.interruptKernelFailed({
              error: err,
              kernelRef: action.payload.kernelRef
            })
          )
        )
      );
    })
  );
開發者ID:nteract,項目名稱:nteract,代碼行數:58,代碼來源:websocket-kernel.ts

示例4: ofType

export const fetchContentEpic = (
  action$: ActionsObservable<actions.FetchContent>
) =>
  action$.pipe(
    ofType(actions.FETCH_CONTENT),
    tap((action: actions.FetchContent) => {
      // If there isn't a filepath, save-as it instead
      if (!action.payload.filepath) {
        throw new Error("fetch content needs a path");
      }
    }),
    // Switch map since we want the last load request to be the lead
    switchMap(action => {
      const filepath = action.payload.filepath;

      return forkJoin(
        readFileObservable(filepath),
        statObservable(filepath),
        // Project onto the Contents API response
        (content: Buffer, stat: fs.Stats): contents.IContent =>
          createContentsResponse(filepath, stat, content)
      ).pipe(
        // Timeout after one minute
        timeout(60 * 1000),
        map((model: contents.IContent<"notebook">) => {
          if (model.type !== "notebook") {
            throw new Error(
              "Attempted to load a non-notebook type from desktop"
            );
          }
          if (model.content === null) {
            throw new Error("No content loaded for notebook");
          }

          return actions.fetchContentFulfilled({
            filepath: model.path,
            model,
            kernelRef: action.payload.kernelRef,
            contentRef: action.payload.contentRef
          });
        }),
        catchError((err: Error) =>
          of(
            actions.fetchContentFailed({
              filepath,
              error: err,
              kernelRef: action.payload.kernelRef,
              contentRef: action.payload.contentRef
            })
          )
        )
      );
    })
  );
開發者ID:nteract,項目名稱:nteract,代碼行數:54,代碼來源:loading.ts

示例5: ofType

export const loadConfigEpic = (action$: ActionsObservable<Actions>) =>
  action$.pipe(
    ofType(actions.LOAD_CONFIG),
    switchMap(() =>
      readFileObservable(CONFIG_FILE_PATH).pipe(
        map(data =>
          actions.configLoaded({
            config: JSON.parse(data.toString())
          })
        )
      )
    )
  );
開發者ID:nteract,項目名稱:nteract,代碼行數:13,代碼來源:config.ts

示例6: ofType

export const fetchKernelspecsEpic = (
  action$: ActionsObservable<actions.FetchKernelspecs>,
  state$: any
) =>
  action$.pipe(
    ofType(actions.FETCH_KERNELSPECS),
    mergeMap((action: actions.FetchKernelspecs) => {
      const {
        payload: { hostRef, kernelspecsRef }
      } = action;
      const state = state$.value;

      const host = selectors.currentHost(state);
      if (host.type !== "jupyter") {
        // Dismiss any usage that isn't targeting a jupyter server
        return empty();
      }
      const serverConfig: ServerConfig = selectors.serverConfig(host);

      return kernelspecs.list(serverConfig).pipe(
        map(data => {
          const defaultKernelName = data.response.default;
          const kernelspecs: { [key: string]: KernelspecProps } = {};
          Object.keys(data.response.kernelspecs).forEach(key => {
            const value = data.response.kernelspecs[key];
            kernelspecs[key] = {
              name: value.name,
              resources: value.resources,
              argv: value.spec.argv,
              displayName: value.spec.display_name,
              env: value.spec.env,
              interruptMode: value.spec.interrupt_mode,
              language: value.spec.language,
              metadata: value.spec.metadata
            };
          });
          return actions.fetchKernelspecsFulfilled({
            hostRef,
            kernelspecsRef,
            defaultKernelName,
            kernelspecs
          });
        }),
        catchError(error => {
          return of(actions.fetchKernelspecsFailed({ kernelspecsRef, error }));
        })
      );
    })
  );
開發者ID:nteract,項目名稱:nteract,代碼行數:49,代碼來源:kernelspecs.ts

示例7: watchSpawn

export function watchSpawn(
  action$: ActionsObservable<actions.NewKernelAction>
) {
  return action$.pipe(
    ofType(actions.LAUNCH_KERNEL_SUCCESSFUL),
    switchMap(
      (action: actions.NewKernelAction): Observable<Actions> => {
        if (action.payload.kernel.type !== "zeromq") {
          throw new Error("kernel.type is not zeromq.");
        }
        if (!action.payload.kernel.spawn) {
          throw new Error("kernel.spawn is not provided.");
        }
        const spawn: ChildProcess = action.payload.kernel.spawn;
        return new Observable((observer: Subscriber<Actions>) => {
          spawn.on("error", error => {
            // We both set the state and make it easy for us to log the error
            observer.next(
              actions.setExecutionState({
                kernelStatus: "process errored",
                kernelRef: action.payload.kernelRef
              })
            );
            observer.error({ type: "ERROR", payload: error, err: true });
            observer.complete();
          });
          spawn.on("exit", () => {
            observer.next(
              actions.setExecutionState({
                kernelStatus: "process exited",
                kernelRef: action.payload.kernelRef
              })
            );
            observer.complete();
          });
          spawn.on("disconnect", () => {
            observer.next(
              actions.setExecutionState({
                kernelStatus: "process disconnected",
                kernelRef: action.payload.kernelRef
              })
            );
            observer.complete();
          });
        });
      }
    )
  );
}
開發者ID:nteract,項目名稱:nteract,代碼行數:49,代碼來源:zeromq-kernels.ts

示例8: of

export const interruptKernelEpic = (
  action$: ActionsObservable<actions.InterruptKernel>,
  state$: StateObservable<AppState>
): Observable<InterruptActions> =>
  action$.pipe(
    ofType(actions.INTERRUPT_KERNEL),
    // This epic can only interrupt direct zeromq connected kernels
    filter(() => selectors.isCurrentKernelZeroMQ(state$.value)),
    // If the user fires off _more_ interrupts, we shouldn't interrupt the in-flight
    // interrupt, instead doing it after the last one happens
    concatMap(
      (action: actions.InterruptKernel): Observable<InterruptActions> => {
        const kernel = selectors.currentKernel(state$.value);
        if (!kernel) {
          return of(
            actions.interruptKernelFailed({
              error: new Error("Can't interrupt a kernel we don't have"),
              kernelRef: action.payload.kernelRef
            })
          );
        }

        if (kernel.type !== "zeromq" || !kernel.spawn) {
          return of(
            actions.interruptKernelFailed({
              error: new Error("Invalid kernel type for interrupting"),
              kernelRef: action.payload.kernelRef
            })
          );
        }

        const spawn = kernel.spawn;

        //
        // From the node.js docs
        //
        // > The ChildProcess object may emit an 'error' event if the signal cannot be delivered.
        //
        // This is instead handled in the watchSpawnEpic below
        spawn.kill("SIGINT");

        return of(
          actions.interruptKernelSuccessful({
            kernelRef: action.payload.kernelRef
          })
        );
      }
    )
  );
開發者ID:nteract,項目名稱:nteract,代碼行數:49,代碼來源:zeromq-kernels.ts

示例9: acquireKernelInfo

export const acquireKernelInfoEpic = (
  action$: ActionsObservable<actions.NewKernelAction>
) =>
  action$.pipe(
    ofType(actions.LAUNCH_KERNEL_SUCCESSFUL),
    switchMap((action: actions.NewKernelAction) => {
      const {
        payload: {
          kernel: { channels },
          kernelRef,
          contentRef
        }
      } = action;
      return acquireKernelInfo(channels, kernelRef, contentRef);
    })
  );
開發者ID:nteract,項目名稱:nteract,代碼行數:16,代碼來源:kernel-lifecycle.ts


注:本文中的redux-observable.ActionsObservable.pipe方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。