为什么我使用有效的LatestFrom操作从选择器获取具有操作观测器属性的对象



;res";value是一个对象,它不检索与选择器相关的数据,在其他地方工作,但实际上是获取这个对象。为什么会发生这种情况?

constructor(
private serviceStore: Store<DataState>,
) {
searchForLatest$ = createEffect(() =>
this._actions.pipe(
ofType<GetLatestRequestService>(GetLatestData),
withLatestFrom(({ id }) => 
this.serviceStore.select(getlatestData(id)),
mergeMap(res => {


actionsObserver: { 
closed: false,
hasError: false,
isStopped: false,
observers: [SkipSubscriber],
thrownError: null,
_isScalar: false,
}
operator: {
compare: undefined
keySelector: undefined
}
reducerManager: {
closed: false
dispatcher: DevtoolsDispatcher {_isScalar: false, observers: Array(1), closed: false, 
isStopped: false, hasError: false, …}
hasError: false
initialState: undefined
isStopped: false
observers: [MapSubscriber]
reducerFactory: (reducers, initialState) => {…}
reducers: {uiContext: ƒ, parties: ƒ, user: ƒ, organizationsDetail: ƒ, activeRoute: ƒ, …}
thrownError: null
_isScalar: false
_value: (state, action) =>
}
Source: {
actionsObserver: ActionsSubject {_isScalar: false, observers: Array(1), closed: false, 
isStopped: false, hasError: false, …}
operator: MapOperator {thisArg: undefined, project: ƒ}
reducerManager: ReducerManager {_isScalar: false, observers: Array(1), closed: false, 
isStopped: false, hasError: false, …}
source: Store {_isScalar: false, actionsObserver: ActionsSubject, reducerManager: 
ReducerManager, source: Observable}
_isScalar: false

}_isScalar:错误

v13中的effect更新了从选择器检索最新数据的方法,我需要使用concatLatestFrom运算符来获取数据。

@Injectable()
export class CollectionEffects {
addBookToCollectionSuccess$ = createEffect(
() =>
this.actions$.pipe(
ofType(CollectionApiActions.addBookSuccess),
concatLatestFrom(action => this.store.select(fromBooks.getCollectionBookIds)),
tap(([action, bookCollection]) => {
if (bookCollection.length === 1) {
window.alert('Congrats on adding your first book!');
} else {
window.alert('You have added book number ' + bookCollection.length);
}
})
),
{ dispatch: false }
);
constructor(
private actions$: Actions,
private store: Store<fromBooks.State>
) {}
}

注意:出于性能原因,请使用concatLatestFrom等平坦化运算符来防止选择器在发出正确操作之前激发。

相关内容

  • 没有找到相关文章

最新更新