可以使用map操作符将action对象的参数映射到新的对象中,然后使用withLatestFrom操作符将该对象与所需的参数合并,并将其传递给效用方法。
以下是一个例子:
import { ofType } from '@ngrx/effects';
import { tap, withLatestFrom, map } from 'rxjs/operators';
export class SomeEffects {
someEffect$ = createEffect(() =>
this.actions$.pipe(
ofType(SomeAction),
map((action) => {
return { payload: action.payload }; // create new object with necessary param
}),
withLatestFrom(this.store.select(someSelector)), // combine the created object with the parameter
tap(([obj, param]) => {
// use obj.payload and param here
})
)
);
constructor(private actions$: Actions, private store: Store) {}
}