本文整理匯總了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);
})
);