本文整理匯總了TypeScript中@ngrx/effects.Effect函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript Effect函數的具體用法?TypeScript Effect怎麽用?TypeScript Effect使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Effect函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: persistTodos
@Effect({ dispatch: false })
persistTodos() {
return this.actions$.pipe(
ofType<ActionTodosPersist>(TodosActionTypes.PERSIST),
tap(action =>
this.localStorageService.setItem(TODOS_KEY, action.payload.todos)
)
);
}
示例2: login
@Effect({ dispatch: false })
login() {
return this.actions$.pipe(
ofType<ActionAuthLogin>(AuthActionTypes.LOGIN),
tap(() =>
this.localStorageService.setItem(AUTH_KEY, { isAuthenticated: true })
)
);
}
示例3: 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 });
})
);
}
示例4: 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)
)
);
}
示例5: 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
})
)
);
}
示例6: login
@Effect({ dispatch: false })
login(): Observable<Action> {
return this.actions$
.ofType(AuthActionTypes.LOGIN)
.pipe(
tap(action =>
this.localStorageService.setItem(AUTH_KEY, { isAuthenticated: true })
)
);
}
示例7: logout
@Effect({ dispatch: false })
logout() {
return this.actions$.pipe(
ofType<ActionAuthLogout>(AuthActionTypes.LOGOUT),
tap(() => {
this.router.navigate(['']);
this.localStorageService.setItem(AUTH_KEY, { isAuthenticated: false });
})
);
}
示例8: 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
);
})
);
}
示例9: 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 }))
)
)
)
);
}
示例10: 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 })
)
)
)
);
}