Last active
August 29, 2015 14:25
-
-
Save tadjik1/db2d3bd5ac2db5ac60e0 to your computer and use it in GitHub Desktop.
reducers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a lot, @gaearon!