然而,这是一种糟糕的做法,有关更多信息,请参阅NgRx ESLint文档中的No Multiple Actions In Effects...
您可以对此使用` `switchMapDispatching Multiple Actions from NGRX Effects
@Effect getUsers$=this.actions$.ofType('GET_USERS','CANCEL_GET_USERS').withLatestFrom(this.userSelectors.needUsers$).filter(([action,needUsers])=>needUsers).map(([action,needUsers])=>action).switchMap(action=>action.type==='CANCEL_GET_USERS'?Observable.of():this.getUsers().map(users=...
Note that MockStateUpdates is a replay subject with an infinite buffer size letting you queue up multiple actions / state changes to be sent to your effect. Migrating from store-saga @ngrx/effects is heavily inspired by store-saga making it easy to translate sagas into effects. Rewriting ...
actions$.ofType(LOAD_DATA) .pipe(switchMap(() => { return this.apiService.getData().pipe( map(data => new LOAD_DATA_SUCCESS(data)), catchError(error => of(new LOAD_DATA_FAILURE(error))) ); }); You can see that the effect is listening for the LOAD_DATA action, and then calls...
完成,然后返回一个包含聚合响应的数组,如下所示。x一个一个一个一个x一个一个二个x ...
actions$.pipe( // you can pass in multiple actions here that will trigger the same effect ofType(MenusActions.appLoaded.type, MenusActions.addMenuItemSuccess), switchMap(() => this.apiService.getItems().pipe( map((menuItems) => MenusActions.fetchMenuSuccess({ menuItems: menuItems }) ),...
Integration with: ngrx/storeRxJS powered state management, inspired byRedux ngrx/effectsSide effect model for @ngrx/store ngx-translatefor i18n Usage is optional but on by default Up to you and your team how you want to utilize it. It can be easily removed if not needed. ...
See example below for ng-repeat and ng-click: Usage All Angular snippets starts with "ng-". Multiple snippets come in multiple variations. For instance when you want to create a new component you can choose between having the template and css inline or not: ...
import { Injectable } from '@angular/core'; import { Actions, createEffect, ofType } from '@ngrx/effects'; import { map, switchMap } from 'rxjs/operators'; import * as fromActions from '../actions/article.actions'; import { ArticleService } from '../services/article.service'; @Inject...