{"action":"created","issue":{"url":"https://api.github.com/repos/ReSwift/ReSwift/issues/69","labels_url":"https://api.github.com/repos/ReSwift/ReSwift/issues/69/labels{/name}","comments_url":"https://api.github.com/repos/ReSwift/ReSwift/issues/69/comments","events_url":"https://api.github.com/repos/ReSwift/ReSwift/issues/69/events","html_url":"https://github.com/ReSwift/ReSwift/issues/69","id":130033238,"number":69,"title":"Passing \"sub Stores\" for subscription","user":{"login":"raheelahmad","id":54114,"avatar_url":"https://avatars.githubusercontent.com/u/54114?v=3","gravatar_id":"","url":"https://api.github.com/users/raheelahmad","html_url":"https://github.com/raheelahmad","followers_url":"https://api.github.com/users/raheelahmad/followers","following_url":"https://api.github.com/users/raheelahmad/following{/other_user}","gists_url":"https://api.github.com/users/raheelahmad/gists{/gist_id}","starred_url":"https://api.github.com/users/raheelahmad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/raheelahmad/subscriptions","organizations_url":"https://api.github.com/users/raheelahmad/orgs","repos_url":"https://api.github.com/users/raheelahmad/repos","events_url":"https://api.github.com/users/raheelahmad/events{/privacy}","received_events_url":"https://api.github.com/users/raheelahmad/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ReSwift/ReSwift/labels/Question","name":"Question","color":"d4c5f9"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-01-30T20:33:32Z","updated_at":"2016-01-31T19:12:17Z","closed_at":null,"body":"This comes up when passing down stores as dependencies.\r\n\r\nCurrently being able to subscribe for a sub-state is awesome, as the `newState`  implementation is filtered down.\r\nIt would be nice to bring the same `State` filtering to `Store`s.\r\n\r\nIn other words, be able to generate sub-stores from the main store (just as a lens; there will still be a single concrete store).\r\nThen we can pass the sub-store so that subselection is even more filtered.\r\n\r\nAs an example:\r\n\r\n```swift\r\nstruct InstrumentState: StateType {\r\n    let allInstruments: [Instrument]\r\n    let currentIndex: Int?\r\n}\r\n\r\nprotocol HasInstrumentState {\r\n  var instrumentsState: InstrumentsState { get }\r\n}\r\n\r\nstruct AppState: StateType, HasInstrumentState {\r\n  let instrumentState: InstrumentState\r\n}\r\n\r\n\r\nclass SmallSubscriber: StoreSubscriber {\r\n\r\n  // --- Subscriber can then just expect a \"smaller\" Store\r\n  init(store: Store<InstrumentState>) {\r\n      store.subscribe(self) {\r\n          return $0.current\r\n      }\r\n  }\r\n}\r\n\r\n// But if we start with appState\r\nlet instrumentsState =  InstrumentState(allInstruments: [...], currentIndex: 0)\r\nlet appState = AppState(instrumentState: instrumentsState)\r\nlet mainStore = Store<AppState>(reducer: MyReducer(), state: appState)\r\n\r\n// then we can't pass that store to our subscriber:\r\nlet subscriber = SmallSubscriber(store: mainStore)\r\n```\r\n\r\n- we then expose minimal information\r\n- better at scaling: large apps may have deep nesting of states in the store. Being able to pass a smaller store of a deeper nesting would be great\r\n\r\nMaybe this is already possible?\r\n"},"comment":{"url":"https://api.github.com/repos/ReSwift/ReSwift/issues/comments/177589296","html_url":"https://github.com/ReSwift/ReSwift/issues/69#issuecomment-177589296","issue_url":"https://api.github.com/repos/ReSwift/ReSwift/issues/69","id":177589296,"user":{"login":"raheelahmad","id":54114,"avatar_url":"https://avatars.githubusercontent.com/u/54114?v=3","gravatar_id":"","url":"https://api.github.com/users/raheelahmad","html_url":"https://github.com/raheelahmad","followers_url":"https://api.github.com/users/raheelahmad/followers","following_url":"https://api.github.com/users/raheelahmad/following{/other_user}","gists_url":"https://api.github.com/users/raheelahmad/gists{/gist_id}","starred_url":"https://api.github.com/users/raheelahmad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/raheelahmad/subscriptions","organizations_url":"https://api.github.com/users/raheelahmad/orgs","repos_url":"https://api.github.com/users/raheelahmad/repos","events_url":"https://api.github.com/users/raheelahmad/events{/privacy}","received_events_url":"https://api.github.com/users/raheelahmad/received_events","type":"User","site_admin":false},"created_at":"2016-01-31T19:12:17Z","updated_at":"2016-01-31T19:12:17Z","body":"I am not sure what a good \"Swifty\" design would be, yet.\r\n\r\nLooking at Om, the analog would the concept of [\"cursor\"](https://github.com/omcljs/om/wiki/Cursors)."}}