Skip to content

Instantly share code, notes, and snippets.

@tadjik1
Last active August 29, 2015 14:25
Show Gist options
  • Save tadjik1/db2d3bd5ac2db5ac60e0 to your computer and use it in GitHub Desktop.
Save tadjik1/db2d3bd5ac2db5ac60e0 to your computer and use it in GitHub Desktop.
reducers
const state = {
users: {
list: {id1: user1, id2: user2},
followers: {id1: [id2], id2: [id1]},
following: {id1: [id2], id2: [id1]},
interestingPersons: {id1: [id2], id2: [id1]},
...
}
}
...
class MyComponent {
render() {
const { users } = Store.getState();
// how to get followers and followings for user id=id1 ?
// this way:
const followers = users.followers[id1].map((id) => {state.list[id]});
const followings = users.followings[id1].map((id) => {state.list[id]});
// the problem is: I know inside my component about state structure.
// But I want to know about it only in reducers
// cause this is the place when data changes.
}
}
@gaearon
Copy link

gaearon commented Jul 20, 2015

Use composable selectors: http://github.com/faassen/reselect
These are the same as NuclearJS “getters”: https://github.com/optimizely/nuclear-js#getters

@tadjik1
Copy link
Author

tadjik1 commented Jul 20, 2015

Thanks a lot, @gaearon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment