{"action":"created","issue":{"url":"https://api.github.com/repos/redux-saga/redux-saga/issues/124","repository_url":"https://api.github.com/repos/redux-saga/redux-saga","labels_url":"https://api.github.com/repos/redux-saga/redux-saga/issues/124/labels{/name}","comments_url":"https://api.github.com/repos/redux-saga/redux-saga/issues/124/comments","events_url":"https://api.github.com/repos/redux-saga/redux-saga/issues/124/events","html_url":"https://github.com/redux-saga/redux-saga/issues/124","id":134149937,"number":124,"title":"Multiple `takeLatest` in saga root ?","user":{"login":"Grmiade","id":11244106,"avatar_url":"https://avatars3.githubusercontent.com/u/11244106?v=3","gravatar_id":"","url":"https://api.github.com/users/Grmiade","html_url":"https://github.com/Grmiade","followers_url":"https://api.github.com/users/Grmiade/followers","following_url":"https://api.github.com/users/Grmiade/following{/other_user}","gists_url":"https://api.github.com/users/Grmiade/gists{/gist_id}","starred_url":"https://api.github.com/users/Grmiade/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Grmiade/subscriptions","organizations_url":"https://api.github.com/users/Grmiade/orgs","repos_url":"https://api.github.com/users/Grmiade/repos","events_url":"https://api.github.com/users/Grmiade/events{/privacy}","received_events_url":"https://api.github.com/users/Grmiade/received_events","type":"User","site_admin":false},"labels":[{"id":293021649,"url":"https://api.github.com/repos/redux-saga/redux-saga/labels/question","name":"question","color":"cc317c","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":11,"created_at":"2016-02-17T01:33:15Z","updated_at":"2017-06-05T14:15:30Z","closed_at":"2016-02-18T15:08:45Z","body":"I can't have several `takeLatest` in my saga root, it's normal ?\n\n``` javascript\nexport default function* root() {\n  yield* takeLatest(Actions.LOGIN, login);\n  yield* takeLatest(Actions.LOGOUT, logout);\n}\n```\n\nOnly the one `takeLatest` is take into account :/\n"},"comment":{"url":"https://api.github.com/repos/redux-saga/redux-saga/issues/comments/306198483","html_url":"https://github.com/redux-saga/redux-saga/issues/124#issuecomment-306198483","issue_url":"https://api.github.com/repos/redux-saga/redux-saga/issues/124","id":306198483,"user":{"login":"panzerdp","id":1078719,"avatar_url":"https://avatars2.githubusercontent.com/u/1078719?v=3","gravatar_id":"","url":"https://api.github.com/users/panzerdp","html_url":"https://github.com/panzerdp","followers_url":"https://api.github.com/users/panzerdp/followers","following_url":"https://api.github.com/users/panzerdp/following{/other_user}","gists_url":"https://api.github.com/users/panzerdp/gists{/gist_id}","starred_url":"https://api.github.com/users/panzerdp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/panzerdp/subscriptions","organizations_url":"https://api.github.com/users/panzerdp/orgs","repos_url":"https://api.github.com/users/panzerdp/repos","events_url":"https://api.github.com/users/panzerdp/events{/privacy}","received_events_url":"https://api.github.com/users/panzerdp/received_events","type":"User","site_admin":false},"created_at":"2017-06-05T14:15:30Z","updated_at":"2017-06-05T14:15:30Z","body":"First of all, thanks for this awesome library!\r\n\r\nI faced almost the same issue, but with the difference that I need to take latest action from a collection of different types.\r\nUnfortunately `takeLatest('ACTION', handler)` works with a single type of action.\r\n\r\nI implemented a custom effect named `takeMultipleLatest()` that accepts an object with keys as actions and values as corresponding handlers:\r\n\r\n```javascript\r\nfunction* takeMultipleLatestSaga(sagasByPatterns, ...args) {\r\n  const patterns = Object.keys(sagasByPatterns);\r\n  const task = yield fork(function* () {\r\n    let lastTask;\r\n    while (true) {\r\n      const action = yield take(patterns);\r\n      if (lastTask) {\r\n        yield cancel(lastTask);\r\n      }\r\n      lastTask = yield fork(sagasByPatterns[action.type], ...args.concat(action));\r\n    }\r\n  });\r\n  return task;\r\n}\r\n\r\nexport function takeMultipleLatest(sagasByPatterns) {\r\n  return call(takeMultipleLatestSaga, sagasByPatterns);\r\n}\r\n```\r\nThen it can be used almost the same as `takeLatest()`, but with the difference that it supports multiple actions from which only the latest will be taken and other ones cancelled:\r\n\r\n```javascript\r\n  yield takeMultipleLatest({\r\n    'ACTION1': handlerForAction1,\r\n    'ACTION2': handlerForAction2\r\n  });\r\n```\r\nI hope someone will find it useful!\r\n\r\n"}}
{"actor":{"display_login":"panzerdp"}}