一起使用 @ngrx/effects 和 firebase 时出现问题。立即触发成功操作

Problems using @ngrx/effects and firebase together. Success action is triggered instantly

我将 FirebaseAngularFirengrx/effects(所有内容的最新版本)一起使用。

看看下面的效果:

  createGroupRequest$ = createEffect(() =>
    this.actions$.pipe(
      ofType(CreateGroupActions.createGroupRequest),
      switchMap(action =>
        of(this.afs.collection<Group>('groups').add(action.group))
          .pipe(
            map(() => CreateGroupActions.createGroupSuccess()), // This is fired instantly, NOT when the request is done
            catchError(error => of(CreateGroupActions.createGroupFailure(error)))
          ))
    )
  );

  constructor(
    private actions$: Actions,
    private store: Store<AppState>,
    private afs: AngularFirestore,
  ) {
  }

我的主要问题是我的 成功操作是立即触发的 ,而不是 add() 请求完成时触发的。我很确定这是因为 firebase 的 collection.add() 函数 returns 是一个承诺而不是可观察的。

我尝试用 of() 包装它以使其成为 Observable,但没有帮助。有什么想法吗?

我已经解决了

of() 更改为 from() 使其生效。

当我在官方文档中阅读这些运算符时,我注意到 of() 实际上并没有将参数转换为 Observable,而 from() 正是这样做的。