redux-saga 中的 `select` 效果有什么意义?
What's the point of the `select` effect in redux-saga?
redux-saga 将自己描述为
a library that aims to make application side effects
(i.e.
asynchronous things like data fetching and impure things like
accessing the browser cache) easier to manage.
select
效果刚好用到get a slice of the current Store's state
。它根本不会产生任何副作用(没有 I/O 操作,没有突变等)。这只是一个纯函数操作。为什么将纯功能操作设计为效果?
因为您的 saga 代码 none 总体上应该直接与商店交互。无论您的 saga 需要做什么,无论是进行 AJAX 调用、分派动作还是其他任何事情,都可以通过生成效果描述并要求中间件为您完成这些工作来完成。您的 saga 无法直接访问商店以调用 dispatch()
,因此它也没有理由直接访问 getState()
。
redux-saga 将自己描述为
a library that aims to make application
side effects
(i.e. asynchronous things like data fetching and impure things like accessing the browser cache) easier to manage.
select
效果刚好用到get a slice of the current Store's state
。它根本不会产生任何副作用(没有 I/O 操作,没有突变等)。这只是一个纯函数操作。为什么将纯功能操作设计为效果?
因为您的 saga 代码 none 总体上应该直接与商店交互。无论您的 saga 需要做什么,无论是进行 AJAX 调用、分派动作还是其他任何事情,都可以通过生成效果描述并要求中间件为您完成这些工作来完成。您的 saga 无法直接访问商店以调用 dispatch()
,因此它也没有理由直接访问 getState()
。