我正在使用react-observable并在我的React项目中重新选择。我想要实现的就是这样:
//选择器
export const getItem = createSelector(getItemsState, state => state.item);
现在在史诗中,我想做这样的事情:
const addItem$: Epic = (action$: Observable<Actions>, state$) =>
action$.pipe(
filter(action => action.type === 'ADD_ITEM'),
withLatestFrom(state$.select(getItem)), // Just use there my selector which is written.
switchMap((item) => {
return ItemsApi.addItem(item);
},
),
);
是否有可能?谢谢您的帮助!
我注意到如何使用它。因此,如果我想接收选择器中提供的内容,则需要执行以下操作:
const addItem$: Epic = (action$: Observable<Actions>, state$) =>
action$.pipe(
filter(action => action.type === 'ADD_ITEM'),
withLatestFrom(getItem(state$.value)),
switchMap(([, item]) => {
return ItemsApi.addItem(item);
},
),
);