投稿のリストを表示するReduxアプリケーションがあります。私はその後、私はvisible_post_ids
の内容を置き換え、posts
に追加し、いくつかの記事を読み込むたびイディオム・リダックス:複数のアクションをディスパッチする
{
posts: [
{id: 1, title: 'My Post'},
{id: 2, title: 'Also this one'},
{id: 3, title: 'Other Post'}
],
visible_post_ids: [1, 2]
}
:状態は多かれ少なかれ、このです。
これは、ロードの記事のための私の行動の作成者である:
function loadPosts (filters) {
return function (dispatch, getState) {
return fetch(`/posts.json?filters=${filters}`)
.then((response) => response.json())
.then((posts) => {
dispatch(postsLoaded(posts)) // Will update `posts`
const postIds = posts.map((post) => post.id)
dispatch(updateVisiblePosts(postIds)) // Will update `visible_post_ids`
})
}
}
私の質問は:それは、サンクから2つ(またはそれ以上)のイベントをディスパッチするために慣用のですか?それとも、私は1つだけ派遣し、それをさまざまな減速機で扱うべきですか?