Rxjs 需要了解Ngrx效应的帮助吗

Rxjs 需要了解Ngrx效应的帮助吗,rxjs,ngrx,ngrx-store,ngrx-effects,Rxjs,Ngrx,Ngrx Store,Ngrx Effects,Ngrx文档,用于使用从存储区选择的状态的效果 国家(无双关语) …并提供了示例: addBookToCollectionSuccess$=createEffect(()=>this.actions$.pipe( 类型(CollectionPaactions.addBookSuccess), concatMap(action=>of(action).pipe( withLatestFrom(this.store.select(fromBooks.GetCollectionBookId)) )),

Ngrx文档,用于使用从存储区选择的状态的效果 国家(无双关语)

…并提供了示例:

addBookToCollectionSuccess$=createEffect(()=>this.actions$.pipe(
类型(CollectionPaactions.addBookSuccess),
concatMap(action=>of(action).pipe(
withLatestFrom(this.store.select(fromBooks.GetCollectionBookId))
)),
点击(([action,bookCollection])=>console.log('whatever'))
),{dispatch:false}
);
该示例后来更改为使用
concatLatestFrom
,但这在这里并不重要。我感兴趣的是理解最初的建议。我想我理解这样做的意图,即除了源操作触发之外,避免从
GetCollectionBookId
处理
withLatestFrom
的结果,但我不理解为什么解决方案需要使用
of(action)
withLatestFrom
包装到一个手动构建的可观察对象中。这样的东西不是同样有效而且可读性更好吗

concatMap(()=>this.store.select(selectedbookids.pipe(first()),

我对Rxjs的理解不是很好,经过几天的努力,我怀疑我仍然遗漏了一些东西。

如果您只需要选定的状态,您的建议应该很有效:

concatMap(() => this.store.select(selectSelectedBookIds).pipe(first())),
concatMap(action => of(action).pipe(
  withLatestFrom(this.store.select(fromBooks.getCollectionBookIds))
)),
但是,如果您还需要操作本身,则以下内容将传递一个包含操作和选定状态的数组:

concatMap(() => this.store.select(selectSelectedBookIds).pipe(first())),
concatMap(action => of(action).pipe(
  withLatestFrom(this.store.select(fromBooks.getCollectionBookIds))
)),