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