为什么即使我添加了 takeUntil 和 skipWhile,ngrx return 2 个对象?

Why ngrx return 2 objects even if I add takeUntil and skipWhile?

在我的情况下,我的出版物应该只有一个数组列表。但我有 2 个列表,第一个是空的,第二个是我的真实列表。

我没有在我的 html 中使用异步,它只是我从我的订阅中获取的一个 ngfor。

在我的 ngOnInit 中:

this.publication$ = this.store$.pipe(
    skipWhile(val => val == null),
    select(PublicationFeatureStoreSelectors.selectAllPublicationFeatureItems),
    filter(value => value !== undefined),
);

this.publication$.subscribe(data => {
    takeUntil(this.ngDestroyed$),
        this.piins = data;
    this.publicationAppeared = data.map(a => a._id);
    this.checkIfLiked();
    console.log(data);
});

在我的 ngOnDestroy 中:

this.ngDestroyed$.next();
this.ngDestroyed$.complete();

我的选择器

export const selectAllPublicationsFeatureItems: (
  state: object
) => Publications[] = featureAdapter.getSelectors(selectPublicationsFeatureState).selectAll;

export const selectPublicationsFeatureState: MemoizedSelector<
  object,
  State
> = createFeatureSelector<State>('publicationFeature');

这是我的结果:

[]
(3) [{…}, {…}, {…}]

这是我的减速器:

    case ActionTypes.GET_PUBLICATION_SUCCESS: {

       const myobject = featureAdapter.addAll(action.payload, {
        ...state,
        isLoading: false,
        error: null
      });

      console.log(myobject); // the result is just below

      return myobject;
    }

console.log 的结果:

{ids: Array(3), entities: {…}, isLoading: false, error: null}
entities: {5d0261c743d8c30793eb8d25: {…}, 5d01713c7f353a1a81349299: {…}, 5d0170a67f353a1a81349295: {…}}
error: null
ids: (3) ["5d0261c743d8c30793eb8d25", "5d01713c7f353a1a81349299", "5d0170a67f353a1a81349295"]
isLoading: false
__proto__: Object

和我在reduxTool上得到的结果一模一样

如果您有不使用且不调用第一个数组列表的解决方案,非常感谢。

我几乎不得不使用我的方法 checkIfLiked() 一次

这看起来 so familiar!

我建议你 tap(console.log) 调试你的流,这样你就可以看到那里发生了什么,比如:

this.publication$ = this.store$.pipe(
  tap(val => console.log('skipWhile', val, val == null)),
  skipWhile(val => val == null),
  select(PublicationFeatureStoreSelectors.selectAllPublicationFeatureItems),
  tap(value => console.log('filter', value, value !== undefined)),
  filter(value => value !== undefined),
);

并且输出将清楚地表明哪些条件通过以及出现了什么问题。
祝你好运!