{"action":"created","issue":{"url":"https://api.github.com/repos/vuejs/vuex/issues/381","repository_url":"https://api.github.com/repos/vuejs/vuex","labels_url":"https://api.github.com/repos/vuejs/vuex/issues/381/labels{/name}","comments_url":"https://api.github.com/repos/vuejs/vuex/issues/381/comments","events_url":"https://api.github.com/repos/vuejs/vuex/issues/381/events","html_url":"https://github.com/vuejs/vuex/issues/381","id":181871703,"number":381,"title":"New module option `subStore`","user":{"login":"ktsn","id":2194624,"avatar_url":"https://avatars.githubusercontent.com/u/2194624?v=3","gravatar_id":"","url":"https://api.github.com/users/ktsn","html_url":"https://github.com/ktsn","followers_url":"https://api.github.com/users/ktsn/followers","following_url":"https://api.github.com/users/ktsn/following{/other_user}","gists_url":"https://api.github.com/users/ktsn/gists{/gist_id}","starred_url":"https://api.github.com/users/ktsn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ktsn/subscriptions","organizations_url":"https://api.github.com/users/ktsn/orgs","repos_url":"https://api.github.com/users/ktsn/repos","events_url":"https://api.github.com/users/ktsn/events{/privacy}","received_events_url":"https://api.github.com/users/ktsn/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/vuejs/vuex/labels/discussion","name":"discussion","color":"d4c5f9"},{"url":"https://api.github.com/repos/vuejs/vuex/labels/proposal","name":"proposal","color":"fbca04"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-10-09T07:30:01Z","updated_at":"2016-10-09T18:24:31Z","closed_at":null,"body":"This proposal is come up from the discussion in #359.\r\n\r\n### Summary of proposal\r\n\r\nModules will have `subStore` option that expects a sub store name. If the option is specified, a sub store will be created under `store.subStores`.\r\n\r\nThe sub store has `state`, `getters`, `dispatch` and `commit` which are same interface as `Vuex.Store` but state will be the local state of corresponding module.\r\n\r\nIf `prefix` option (another proposal #380) is specified, sub store will prefix all getters, actions and mutations types implicitly. For example, if we set `prefix: 'user/'` on sub store module, `subStore.dispatch('login')` will be transformed to `rootStore.dispatch('user/login')`.\r\n\r\n### Why is this worth adding?\r\n\r\nCurrently, we need to collect state, getters, actions and mutations from global namespace when we use them on components even though we separate the application state and logics to each module.\r\n\r\nIt would be good to provide the sub store because we can load all assets in a module at once and use them without prefix.\r\n\r\n### Examples\r\n\r\nModule definition:\r\n\r\n```js\r\nconst userModule = {\r\n  subStore: 'user',\r\n  prefix: 'userModule/'\r\n\r\n  // module assets\r\n  state: { ... },\r\n  getters: {\r\n    isAdmin () { ... }\r\n  },\r\n  actions: {\r\n    login () { ... }\r\n  },\r\n  mutations: {\r\n    setName () { ... },\r\n  }\r\n}\r\n```\r\n\r\nUsage of sub store:\r\n\r\n```js\r\nconst store = new Vuex.Store({\r\n  modules: {\r\n    user: userModule\r\n  }\r\n})\r\n\r\nconst user = store.subStores.user\r\nuser.state.id // -> store.state.user.id\r\nuser.getters.isAdmin // -> store.getters['userModule/isAdmin']\r\nuser.dispatch('login') // -> store.dispatch('userModule/login')\r\nuser.commit('setName') // -> store.commit('userModule/setName')\r\n```\r\n\r\nComponent binding:\r\n\r\n```js\r\ncomputed: {\r\n  // 2nd argument will be sub store name\r\n  ...mapGetters({\r\n    admin: 'isAdmin' // -> admin: 'userModule/isAdmin'\r\n  }, 'user')\r\n}\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/vuejs/vuex/issues/comments/252503174","html_url":"https://github.com/vuejs/vuex/issues/381#issuecomment-252503174","issue_url":"https://api.github.com/repos/vuejs/vuex/issues/381","id":252503174,"user":{"login":"ktsn","id":2194624,"avatar_url":"https://avatars.githubusercontent.com/u/2194624?v=3","gravatar_id":"","url":"https://api.github.com/users/ktsn","html_url":"https://github.com/ktsn","followers_url":"https://api.github.com/users/ktsn/followers","following_url":"https://api.github.com/users/ktsn/following{/other_user}","gists_url":"https://api.github.com/users/ktsn/gists{/gist_id}","starred_url":"https://api.github.com/users/ktsn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ktsn/subscriptions","organizations_url":"https://api.github.com/users/ktsn/orgs","repos_url":"https://api.github.com/users/ktsn/repos","events_url":"https://api.github.com/users/ktsn/events{/privacy}","received_events_url":"https://api.github.com/users/ktsn/received_events","type":"User","site_admin":false},"created_at":"2016-10-09T18:24:31Z","updated_at":"2016-10-09T18:24:31Z","body":"@yyx990803 \r\nI think this feature is not overlap with modules because modules let us divide the concern on *definition time* but they are flatten when we use them. So we need to write prefix for all execution of getters, actions and mutation. This is what the sub store would solves.\r\n\r\n@psi-4ward \r\nNo, vuex will be still single source of truth. Sub stores are just alias of state, getters, actions and mutations for the root store. Maybe this name is a little bad..."}}
{"actor":{"display_login":"ktsn"}}