코드가 있습니다
@Effect()
myEffect$ = this.actions$.pipe(
ofType(MyActions.doSomething),
tap(() => this.store.dispatch(MyActions.doSomething2())),
switchMap(action => {
작동합니다. 탭하기 직전에 필터를 주입해야합니다. switchMap이 작업 값을 잃지 않도록하는 방법은 무엇입니까?
나는 그것을 시도하고있다
@Effect()
myEffect$ = this.actions$.pipe(
ofType(MyActions.doSomething),
switchMap(() => this.store.pipe(select(mySelectors.getAmount), take(1))),
filter(amount => amount <= 0),
tap(() => this.store.dispatch(MyActions.doSomething2())),
switchMap(action => {
....
그러나 그것은 property action.xxxx doesn't exist on type number
분명한 이유를 말합니다 . MyActions.doSomething에서 반환 한 작업 값을 잃지 않는 방법은 무엇입니까?
더 나은 캡슐화를 위해 해당 값에만 적용되는 경우 금액 저장소의 연산자 체인 내에서 필터를 직접 이동합니다. 그런 다음 그 밖의 금액을 내보낼 필요가 없으며 switchMap
작업에 다시 매핑하면됩니다.
@Effect()
myEffect$ = this.actions$.pipe(
ofType(MyActions.doSomething),
switchMap(action => this.store.pipe(
select(mySelectors.getAmount),
take(1),
filter(amount => amount <= 0), // filter amounts here
map(_ => action) // remap to actions
))),
tap(() => this.store.dispatch(MyActions.doSomething2())),
switchMap(action => {
// ...
})
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다