本文整理汇总了TypeScript中redux-observable.ofType函数的典型用法代码示例。如果您正苦于以下问题:TypeScript ofType函数的具体用法?TypeScript ofType怎么用?TypeScript ofType使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ofType函数的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
})
)
)
)
)
);
示例2: ofType
const setActiveKernelEpic = (action$, state$) =>
action$.pipe(
ofType(actionTypes.SET_ACTIVE_KERNEL),
mergeMap(({ payload: { serverId, kernelName } }) => {
const channelPath = [
"entities",
"serversById",
serverId,
"server",
"activeKernelsByName",
kernelName,
"kernel",
"channel"
];
const channel = objectPath.get(state$.value, channelPath);
const actionsArray: Array<{
type: string;
payload: string | { serverId: string; kernelName: string };
}> = [actions.setCurrentKernelName(kernelName)];
if (!channel) {
actionsArray.push(actions.activateKernel({ serverId, kernelName }));
}
return of(...actionsArray);
})
);
示例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 })
)
);
})
);
}
示例4: ofType
const errorHandlingEpics = action$ =>
action$.pipe(
ofType(ERROR),
delay(3000),
take(1),
map(stopError)
);
示例5: ofType
export const GET_TODOLIST_REQUEST = (action$: any) =>
action$.pipe(
ofType(Actions.GET_TODOLIST.REQUEST),
mergeMap((action: any) => {
const userId = getCachedUserId();
let url;
switch (action.payload.todoBoxId) {
case '@all':
url = `/t/user/${userId}/todo`;
break;
case '@task':
url = `/t/user/${userId}/task-todo`;
break;
default:
url = `/t/todo-box/${action.payload.todoBoxId}`;
break;
}
return http
.get(makeApiUrl(url))
.then((data: any) => {
return Actions.GET_TODOLIST.success(
(data || []).map((todo: any) => {
return todo.todoBoxId ? todo : { ...todo, todoBoxId: action.payload.todoBoxId };
})
);
})
.catch(Actions.GET_TODOLIST.failure);
})
);
示例6: 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
})
)
)
);
})
);
示例7: ofType
export const LOGOUT_SUCCESS = (action$: Observable<any>) =>
action$.pipe(
ofType(Actions.LOGOUT.SUCCESS),
mergeMap(() => {
Storage.clear();
window.location.pathname = '/';
return of(Actions.LOGOUT.finish);
})
);
示例8: ofType
export const CHANGE_PASSWORD_REQUEST = (action$: any) =>
action$.pipe(
ofType(Actions.CHANGE_PASSWORD.REQUEST),
mergeMap((action: any) => {
return axios
.post(makeApiUrl(`/user/update-password`), action.payload)
.then(resp => Actions.CHANGE_PASSWORD.success(resp.data))
.catch(Actions.CHANGE_PASSWORD.failure);
})
);
示例9: ofType
export const TASKBOARD_SETTING_UPDATE_REQUEST = (action$: any) =>
action$.pipe(
ofType(Actions.TASKBOARD_SETTING_UPDATE.REQUEST),
mergeMap((action: any) => {
return axios
.patch(`/api/task-board/${action.meta.taskBoardId}/setting`, action.payload)
.then(resp => Actions.TASKBOARD_SETTING_UPDATE.success(resp.data, action.meta))
.catch(Actions.TASKBOARD_SETTING_UPDATE.failure);
})
);