当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript redux-observable.ActionsObservable类代码示例

本文整理汇总了TypeScript中redux-observable.ActionsObservable的典型用法代码示例。如果您正苦于以下问题:TypeScript ActionsObservable类的具体用法?TypeScript ActionsObservable怎么用?TypeScript ActionsObservable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ActionsObservable类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: test

 test("Informs about disconnected kernels, allows reconnection", async () => {
   const state$ = {
     value: {
       core: stateModule.makeStateRecord({
         kernelRef: "fake",
         entities: stateModule.makeEntitiesRecord({
           contents: stateModule.makeContentsRecord({
             byRef: Immutable.Map({
               fakeContent: stateModule.makeNotebookContentRecord()
             })
           }),
           kernels: stateModule.makeKernelsRecord({
             byRef: Immutable.Map({
               fake: stateModule.makeRemoteKernelRecord({
                 channels: null,
                 status: "not connected"
               })
             })
           })
         })
       }),
       app: {
         notificationSystem: { addNotification: jest.fn() }
       }
     }
   };
   const action$ = ActionsObservable.of(
     actions.executeCell({ id: "first", contentRef: "fakeContentRef" })
   );
   const responses = await executeCellEpic(action$, state$)
     .pipe(toArray())
     .toPromise();
   expect(responses).toEqual([]);
 });
开发者ID:nteract,项目名称:nteract,代码行数:34,代码来源:execute.spec.ts

示例2: describe

describe('add$ epic', () => {
  const action$ = ActionsObservable.of({
    type: TodoAction.Constants.ADD_ITEM,
    payload: { label: 'new' },
  });

  it('dispatches the correct action when it is successful', async () => {
    const mockResponse = [{ label: 'new', id: '789', completed: false }, ...mockData];
    const mockService: Todo.Adder = {
      addItem: () => Promise.resolve(mockResponse),
    };

    const expectedOutputActions = {
      type: TodoAction.Constants.SET_TODOS,
      payload: mockResponse,
    };

    const obs = add$(mockService)(action$);
    await expect(obs.toPromise()).resolves.toEqual(expectedOutputActions);
  });

  it('dispatches an error when the call fails', async () => {
    const mockService: Todo.Adder = {
      addItem: () => Promise.reject('error'),
    };

    const expectedOutputActions = {
      type: TodoAction.Constants.REQUEST_FAILED,
      payload: 'Add Item Failed',
    };

    const obs = add$(mockService)(action$);
    await expect(obs.toPromise()).resolves.toEqual(expectedOutputActions);
  });
});
开发者ID:ksaldana1,项目名称:react-native-typescript-todo,代码行数:35,代码来源:epics.ts

示例3: 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

示例4: 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

示例5: test

 test("returns an Observable with an initial state of idle", done => {
   const action$ = ActionsObservable.of({
     type: actionsModule.LAUNCH_KERNEL_SUCCESSFUL,
     payload: {
       kernel: {
         channels: of({
           header: { msg_type: "status" },
           content: { execution_state: "idle" }
         }) as Subject<any>,
         cwd: "/home/tester",
         type: "websocket"
       },
       kernelRef: "fakeKernelRef",
       contentRef: "fakeContentRef",
       selectNextKernel: false
     }
   });
   const obs = watchExecutionStateEpic(action$);
   obs.pipe(toArray()).subscribe(
     // Every action that goes through should get stuck on an array
     actions => {
       const types = actions.map(({ type }) => type);
       expect(types).toEqual([actionsModule.SET_EXECUTION_STATE]);
     },
     err => done.fail(err), // It should not error in the stream
     () => done()
   );
 });
开发者ID:kelleyblackmore,项目名称:nteract,代码行数:28,代码来源:kernel-lifecycle.spec.ts

示例6: test

    test("and allows continuing", async () => {
      let registeredCallback;
      ipc.once = (event, callback) => {
        if (event === "show-message-box-response") {
          registeredCallback = callback;
        }
      };
      ipc.send = (event, data) => {
        expect(event).toBe("show-message-box");
        expect(data.message).toEqual(
          "Unsaved data will be lost. Are you sure you want to quit?"
        );

        // "Yes"
        registeredCallback("dummy-event", 0);
      };

      const state = buildState(true);
      const responses = await closeNotebookEpic(
        ActionsObservable.of(
          actions.closeNotebook({ contentRef: "contentRef1" })
        ),
        { value: state }
      )
        .pipe(toArray())
        .toPromise();

      expect(responses).toEqual([
        coreActions.killKernel({ kernelRef: "kernelRef1", restarting: false }),
        actions.closeNotebookProgress({
          newState: DESKTOP_NOTEBOOK_CLOSING_READY_TO_CLOSE
        })
      ]);
    });
开发者ID:nteract,项目名称:nteract,代码行数:34,代码来源:close-notebook.spec.ts

示例7: empty

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


注:本文中的redux-observable.ActionsObservable类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。