angular - 类型错误:你提供了 'function selectOperator(source$)',但期望的是一个流
我正在尝试按照 ngrx 文档创建一个可复用的选择器管道。
我在我的几个组件中都有这个,所以我想创建一个可重用的选择器
this.bookmarks$ = this.store.pipe(
select(fromBookmarks.selectBookmarksLoading),
filter(loading => loading === false),
concatMap(loading =>
of(loading).pipe(
withLatestFrom(
this.store.select(fromBookmarks.selectCurrentBookmarks),
(_, bookmarks) => {
return bookmarks;
}
)
)
)
);
所以我想出了这个。
export const selectBookmarksAfterLoad = pipe(
select(selectBookmarksLoading),
filter(loading => loading === false),
concatMap(loading =>
of(loading).pipe(
withLatestFrom(select(selectCurrentBookmarks), (_, bookmarks) => {
return bookmarks;
})
)
)
);
并且像这样在我的组件中转换了选择器
this.bookmarks$ = this.store.pipe(fromBookmarks.selectBookmarksAfterLoad);
但我收到这样的错误:
rollbar.umd.min.js:1 TypeError: You provided 'function selectOperator(source$) {
/** @type {?} */
let mapped$;
if (typeof pathOrMapFn === 'string') {
/** @type {?} */
const pathSlices = [(/** @type {?} */ (propsOrPath)), ...paths].filter(Boolean);
mapped$ = source$.pipe(Object(rxjs_operators__WEBPACK_IMPORTED_MODULE_2__["pluck"])(pathOrMapFn, ...pathSlices));
}
else if (typeof pathOrMapFn === 'function') {
mapped$ = source$.pipe(Object(rxjs_operators__WEBPACK_IMPORTED_MODULE_2__["map"])((/**
* @param {?} source
* @return {?}
*/
(source) => pathOrMapFn(source, (/** @type {?} */ (propsOrPath))))));
}
else {
throw new TypeError(`Unexpected type '${typeof pathOrMapFn}' in select operator,` +
` expected 'string' or 'function'`);
}
return mapped$.pipe(Object(rxjs_operators__WEBPACK_IMPORTED_MODULE_2__["distinctUntilChanged"])());
}' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable.