当前位置: 首页>>代码示例>>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;未经允许,请勿转载。