如何在注销时重置 ngrx 效果? NGRX 效果

How to reset ngrx effects on logout ? NGRX Efftects

请告诉我如何重置某些操作(用户注销)的所有效果? 我想重置 LOG_OUT 动作的所有效果。 例如:

  1. 订阅对某些动作的影响
  2. 触发takeUntil()内效
  3. 注销
  4. 重置所有效果
  5. 再次订阅同一动作的相同效果(从第 1 步开始)。

目前第 5 步不起作用,导致 takeUntil() 取消订阅该效果。

问题是 takeUntil 完成了一个 observable:https://github.com/ReactiveX/rxjs/blob/master/src/internal/operators/takeUntil.ts#L85 你不能再次订阅。如果您需要在用户注销后暂停某些效果,我会使用某种过滤:

withLatestFrom(..is logged in selector)
filter((isLoggedIn: boolean) => isLoggedIn)

我添加了 mergeMap 并将 takeUntil 放在那里。现在好看了

 @Effect() createConversation$ = this.actions$.pipe(
    ofType(CREATE_CONVERSATION),
    map((action: CreateConversation) => action.payload),
    withLatestFrom(this.store.pipe(select(selectConversation))),
    mergeMap(([message, mdConversation]) => {
      return this.httpService
        .createConversation(mdConversation.data.taskId, message)
        .pipe(
          map(
            result =>
              new CreateConversationComplete({
                id: result.data.id,
                tmpId: mdConversation.data.id
              })
          ),
          catchError((error: MyError) => {
            if (error.type === MyerrorTypes.NETWORK) {
              return of(new CreateConversationRetry(message));
            }
            if (error.type === MyerrorTypes.APPLICATION) {
              return of(new CreateConversationError(mdConversation.data));
            }
          }),
          takeUntil(this.actions$.pipe(ofType(LOG_OUT)))
        );
    })
  );


@Effect() createConversationRetry$ = this.actions$.pipe(
        ofType(CREATE_CONVERSATION_RETRY),
        mergeMap((action: CustomAction) =>
          of(action).pipe(
            delay(NETWORK_TIMEOUT),
            map(data => new CreateConversation(action.payload)),
            takeUntil(this.actions$.pipe(ofType(LOG_OUT)))
          )
        )
      );