我有以下情况-我在组件内部调度了一个在redux存储中设置字段的函数:
// at this moment, itemsCount is equal to null
dispatch(updateCountOfItems(5)); // updates itemsCount in store
dispatch(fetchItems()); // calls saga that fetches items and its based on itemsCount
和内部sagas:
const itemsCount = yield select((state) => state.itemsCount); // I need itemsCount to be up-to-date (5)
yield call(api.apiCall, itemsCount); // will itemsCount equal to 5? or null?
问题:我可以确定,在sagas中,在sagas中调用api时,itemsCount
是最新的吗?因此,它等于分派的5
吗?我可以确定100%吗?
[调度动作是同步的,所以是的,您可以确定在完成状态下的fetchItems()
更新之前,将不会调度itemsCount
。