{"action":"created","issue":{"url":"https://api.github.com/repos/yelouafi/redux-saga/issues/76","repository_url":"https://api.github.com/repos/yelouafi/redux-saga","labels_url":"https://api.github.com/repos/yelouafi/redux-saga/issues/76/labels{/name}","comments_url":"https://api.github.com/repos/yelouafi/redux-saga/issues/76/comments","events_url":"https://api.github.com/repos/yelouafi/redux-saga/issues/76/events","html_url":"https://github.com/yelouafi/redux-saga/issues/76","id":131132640,"number":76,"title":"Code splitting / dynamically loading sagas","user":{"login":"patrickheeney","id":1407228,"avatar_url":"https://avatars.githubusercontent.com/u/1407228?v=3","gravatar_id":"","url":"https://api.github.com/users/patrickheeney","html_url":"https://github.com/patrickheeney","followers_url":"https://api.github.com/users/patrickheeney/followers","following_url":"https://api.github.com/users/patrickheeney/following{/other_user}","gists_url":"https://api.github.com/users/patrickheeney/gists{/gist_id}","starred_url":"https://api.github.com/users/patrickheeney/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/patrickheeney/subscriptions","organizations_url":"https://api.github.com/users/patrickheeney/orgs","repos_url":"https://api.github.com/users/patrickheeney/repos","events_url":"https://api.github.com/users/patrickheeney/events{/privacy}","received_events_url":"https://api.github.com/users/patrickheeney/received_events","type":"User","site_admin":false},"labels":[{"id":293021646,"url":"https://api.github.com/repos/yelouafi/redux-saga/labels/enhancement","name":"enhancement","color":"84b6eb","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":15,"created_at":"2016-02-03T19:46:10Z","updated_at":"2016-12-03T05:13:12Z","closed_at":"2016-02-21T15:07:12Z","body":"I just discovered `redux-saga` and I am looking to start integrating this into my app. I am currently code splitting my reducers and using [replaceReducer](https://github.com/rackt/redux/blob/6acf9796e6f2f19b6dac15440c473c06a8df1901/src/createStore.js#L192) when they hit the correct route. From the saga examples it looks like they all use a rootSaga. The closest I found to an answer is  https://github.com/yelouafi/redux-saga/issues/23#issuecomment-168762879 but I am not certain if this is the official API and usage. \n\nMy current setup looks something like this: http://stackoverflow.com/a/33045558 which I pasted a snippet below:\n\n``` javascript\nfunction createRoutes(reducerRegistry) {\n  return <Route path=\"/\" component={App}>\n    <Route path=\"async\" getComponent={(location, cb) => {\n      require.ensure([], require => {\n        reducerRegistry.register({async: require('./reducers/async')})\n        cb(null, require('./screens/Async'))\n      })\n    }}/>\n  </Route>\n}\n\nfunction createStore(reducerRegistry) {\n  var rootReducer = createReducer(reducerRegistry.getReducers())\n  var store = createStore(rootReducer)\n\n  reducerRegistry.setChangeListener((reducers) => {\n    store.replaceReducer(createReducer(reducers))\n  })\n\n  return store\n}\n```\n\nFrom the other comment, it sounds like this should be possible, but it looks like sagas need access to the store?\n\n``` javascript\n    <Route path=\"async\" getComponent={(location, cb) => {\n      require.ensure([], require => {\n        reducerRegistry.register({async: require('./reducers/async').default})\n        const sagas = require('./sagas').default\n        // store?\n        runSaga(sagas) \n        // right api usage? where to get the store? does any array work?\n        sagas.forEach(saga => runSaga( saga(store.getState), store )) \n        // only supports one rootSaga, not an array?\n        runSaga( sagas(store.getState), store )\n        cb(null, require('./screens/Async'))\n      })\n    }}/>\n```\n\nIt looks like a middleware approach was discussed in https://github.com/yelouafi/redux-saga/issues/13#issuecomment-168884656 that would have solved this, but it was closed. This could have potentially worked:\n\n``` javascript\n  var store = createStore(rootReducer)\n\n  reducerRegistry.setChangeListener(reducers => {\n    store.replaceReducer(createReducer(reducers))\n  })\n\n  sagaRegistry.setChangeListener(iterator => {\n    store.runSaga(iterator)\n  })\n```\n\nWould this be the official usage? What about \"stopping/removing/disconnecting\" the sagas? Will this work with server side rendering?\n"},"comment":{"url":"https://api.github.com/repos/yelouafi/redux-saga/issues/comments/264617491","html_url":"https://github.com/yelouafi/redux-saga/issues/76#issuecomment-264617491","issue_url":"https://api.github.com/repos/yelouafi/redux-saga/issues/76","id":264617491,"user":{"login":"johanneslumpe","id":3470207,"avatar_url":"https://avatars.githubusercontent.com/u/3470207?v=3","gravatar_id":"","url":"https://api.github.com/users/johanneslumpe","html_url":"https://github.com/johanneslumpe","followers_url":"https://api.github.com/users/johanneslumpe/followers","following_url":"https://api.github.com/users/johanneslumpe/following{/other_user}","gists_url":"https://api.github.com/users/johanneslumpe/gists{/gist_id}","starred_url":"https://api.github.com/users/johanneslumpe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/johanneslumpe/subscriptions","organizations_url":"https://api.github.com/users/johanneslumpe/orgs","repos_url":"https://api.github.com/users/johanneslumpe/repos","events_url":"https://api.github.com/users/johanneslumpe/events{/privacy}","received_events_url":"https://api.github.com/users/johanneslumpe/received_events","type":"User","site_admin":false},"created_at":"2016-12-03T05:13:12Z","updated_at":"2016-12-03T05:13:12Z","body":"@mjrussell that's the way i went for now - only adding new sagas to the store and passing them to `.run` - seems to work fine for now. Hot reloading might still be possible - apart from the fact that it is going to reset the reloaded saga (which might or might not be an acceptable trade-off)."}}
{"actor":{"display_login":"johanneslumpe"}}