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


TypeScript Actions.ofType方法代碼示例

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


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

示例1: logout

 @Effect({ dispatch: false })
 logout(): Observable<Action> {
   return this.actions$.ofType(AuthActionTypes.LOGOUT).pipe(
     tap(action => {
       this.router.navigate(['']);
       this.localStorageService.setItem(AUTH_KEY, { isAuthenticated: false });
     })
   );
 }
開發者ID:gojay,項目名稱:angular-ngrx-material-starter,代碼行數:9,代碼來源:auth.effects.ts

示例2: persistTodos

 @Effect({ dispatch: false })
 persistTodos(): Observable<Action> {
   return this.actions$
     .ofType(TodosActionTypes.PERSIST)
     .pipe(
       tap((action: ActionTodosPersist) =>
         this.localStorageService.setItem(TODOS_KEY, action.payload.todos)
       )
     );
 }
開發者ID:spairo,項目名稱:angular-ngrx-material-starter,代碼行數:10,代碼來源:todos.effects.ts

示例3: persistThemeSettings

 @Effect({ dispatch: false })
 persistThemeSettings(): Observable<Action> {
   return this.actions$.ofType(SETTINGS_CHANGE_THEME).pipe(
     tap(action =>
       this.localStorageService.setItem(SETTINGS_KEY, {
         theme: action.payload
       })
     )
   );
 }
開發者ID:a727891,項目名稱:bb,代碼行數:10,代碼來源:settings.effects.ts

示例4: login

 @Effect({ dispatch: false })
 login(): Observable<Action> {
   return this.actions$
     .ofType(AuthActionTypes.LOGIN)
     .pipe(
       tap(action =>
         this.localStorageService.setItem(AUTH_KEY, { isAuthenticated: true })
       )
     );
 }
開發者ID:spairo,項目名稱:angular-ngrx-material-starter,代碼行數:10,代碼來源:auth.effects.ts

示例5: persistSettings

 @Effect({ dispatch: false })
 persistSettings(): Observable<Action> {
   return this.actions$.ofType(SettingsActionTypes.PERSIST).pipe(
     tap((action: ActionSettingsPersist) => {
       const { settings } = action.payload;
       const { pageAnimations, elementsAnimations } = settings;
       this.localStorageService.setItem(SETTINGS_KEY, settings);
       this.animationsService.updateRouteAnimationType(
         pageAnimations,
         elementsAnimations
       );
     })
   );
 }
開發者ID:gojay,項目名稱:angular-ngrx-material-starter,代碼行數:14,代碼來源:settings.effects.ts

示例6: retrieveStock

 @Effect()
 retrieveStock(): Observable<Action> {
   return this.actions$.ofType(StockMarketActionTypes.RETRIEVE).pipe(
     tap((action: ActionStockMarketRetrieve) =>
       this.localStorageService.setItem(STOCK_MARKET_KEY, {
         symbol: action.payload.symbol
       })
     ),
     distinctUntilChanged(),
     debounceTime(500),
     switchMap((action: ActionStockMarketRetrieve) =>
       this.service
         .retrieveStock(action.payload.symbol)
         .pipe(
           map(stock => new ActionStockMarketRetrieveSuccess({ stock })),
           catchError(error =>
             of(new ActionStockMarketRetrieveError({ error }))
           )
         )
     )
   );
 }
開發者ID:gojay,項目名稱:angular-ngrx-material-starter,代碼行數:22,代碼來源:stock-market.effects.ts

示例7: retrieveStock

 @Effect()
 retrieveStock(): Observable<Action> {
   return this.actions$.ofType(STOCK_MARKET_RETRIEVE).pipe(
     tap(action =>
       this.localStorageService.setItem(STOCK_MARKET_KEY, {
         symbol: action.payload
       })
     ),
     distinctUntilChanged(),
     debounceTime(500),
     switchMap(action =>
       this.service.retrieveStock(action.payload).pipe(
         map(stock => ({
           type: STOCK_MARKET_RETRIEVE_SUCCESS,
           payload: stock
         })),
         catchError(err =>
           of({ type: STOCK_MARKET_RETRIEVE_ERROR, payload: err })
         )
       )
     )
   );
 }
開發者ID:a727891,項目名稱:bb,代碼行數:23,代碼來源:stock-market.effects.ts

示例8: constructor

    constructor(private actions: Actions) {

        this.stepStates = this.actions.ofType<ExecutorOutputAction>(ExecutorOutputAction.type).pipe(
            flatMap((action: ExecutorOutputAction) => {
                const {appID, message} = action;

                const composerMark = "Composer: ";
                const lines        = message.split("\n");

                const composerLogs = lines.reduce((acc, line) => {

                    const composerMarkIndex = line.indexOf(composerMark);
                    if (composerMarkIndex === -1) {
                        return acc;
                    }

                    const composerMessage = line.substr(composerMarkIndex + composerMark.length);

                    try {
                        const data = JSON.parse(composerMessage) as ComposerLogEntry;
                        return acc.concat({appID, data});
                    } catch (ex) {
                        console.warn("Could not parse composer message", composerMessage);
                        return acc;
                    }

                }, []);
                return of(...composerLogs);

            }),
            flatMap(action => {
                const {data} = action;
                const appID  = action.appID;
                if (data.hasOwnProperty("stepId")) {
                    const {status, stepId, message} = data as StepInfoLogEntry;

                    const stepParts        = stepId.split(".");
                    const firstLevelStepID = stepParts[1];
                    const isSubstep = stepParts.length > 2;

                    if (!firstLevelStepID) {
                        if (status === "FAILED") {
                            return of(new ExecutionErrorAction(appID, new ExecutionError(undefined, message, "execution")));
                        }
                        return empty();
                    }

                    switch (status) {
                        case "COMPLETED":
                            if (!isSubstep) {
                                return of(new ExecutionStepCompletedAction(appID, firstLevelStepID));
                            }
                            break;
                        case "FAILED":
                            return of(new ExecutionStepFailedAction(appID, firstLevelStepID, message));
                        case "READY":
                            return of(new ExecutionStepStartedAction(appID, firstLevelStepID));
                    }
                } else if (data.status === "DOCKER_PULL_FAILED") {
                    const {retry} = data as DockerPullTryLogEntry;
                    return of(new ExecutionDockerPullTimeoutAction(appID, Date.now() + retry * 1000));
                }

                return empty();

            })
        );
    }
開發者ID:hmenager,項目名稱:composer,代碼行數:68,代碼來源:executor-output-parser.service.ts

示例9: ExecutionPreparedAction


//.........這裏部分代碼省略.........
                model.class as AppType,
                stepList,
                executionParams.outDir
            ));

            const startRunner = executor.execute(content, jobValue, executionParams).catch(ex => {
                processStillRunning = false;
                throw ex;
            });

            startRunner.then(runner => {

                if (obs.closed) {
                    return;
                }

                this.store.dispatch(new ExecutionStartedAction(appID));

                execution = runner;

                const process = execution.run();

                obs.next(execution.getCommandLineString());

                process.on("exit", (code: number, sig) => {
                    processStillRunning = false;

                    /** Successful completion if exit code is 0 */
                    const isCompleted = code === 0;

                    /**
                     * Killing a process manually will throw either exitCode 143, or
                     * a SIGINT/SIGTERM/SIGKILL in different circumstances, so we check for both
                     * */
                    const isCancelled = code === 143 || sig;


                    if (isCompleted) {
                        this.store.dispatch(new ExecutionCompletedAction(appID));
                        obs.complete();
                        return;

                    } else if (isCancelled) {
                        /**
                         * Cancellation is initially triggered from unsubscribing from killing the process
                         * when unsubscribing from the observable.
                         * ExecutionStopAction is therefore dispatched from the original place.
                         * @see executionUnsubscribe
                         */
                        obs.complete();
                        return;
                    } else {
                        this.store.dispatch(new ExecutionErrorAction(appID, new ExecutionError(code)));
                        obs.error(new Error(`Execution failed with exit code ${code}.`));
                    }

                });

                process.on("error", (err: any) => {
                    if (err.code === "ENOENT" && err.path === "java") {
                        obs.error(new Error("Cannot run Java process. Please check if it is properly installed."));
                        return;
                    }

                    obs.error(new Error(err));
                });

                process.stdout.on("data", data => {
                    obs.next(data.toString());
                });

                process.stderr.on("data", data => {
                    const output = data.toString();
                    this.store.dispatch(new ExecutorOutputAction(appID, output, "stderr"));
                });

            }, ex => {
                this.store.dispatch(new ExecutionRequirementErrorAction(appID, ex.message));
                obs.error(new Error(ex));
            });

            const cleanup = () => {
                if (processStillRunning) {
                    this.store.dispatch(new ExecutionStoppedAction(appID));
                }

                if (execution) {
                    execution.kill();
                }
                obs.complete();
            };

            this.actions.ofType(EXECUTION_STOP).pipe(
                filter((action: ExecutionStopAction) => action.appID === appID),
                take(1)
            ).subscribe(() => cleanup());

            /** @name executionUnsubscribe */
            return () => cleanup();
        });
開發者ID:hmenager,項目名稱:composer,代碼行數:101,代碼來源:executor.service.ts


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