Last active
April 11, 2018 03:50
-
-
Save agoldis/f41930c13682036e2287e9be0df7b257 to your computer and use it in GitHub Desktop.
redux blog
This file contains hidden or 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 initialState = { | |
users: [{ id: "user01", name: "John" }, { id: "user02", name: "Bob" }], | |
tasks: [ | |
{ id: "task01", title: "Wash car", assignee: "user01" }, | |
{ id: "task02", title: "Watch tutorial", assignee: "user01" }, | |
{ id: "task03", title: "Do Homework", assignee: "user02" } | |
], | |
profiles: [ | |
{ id: "profile01", user: "user01", picture: "picture01URL" }, | |
{ id: "profile02", user: "user02", picture: "picture02URL" } | |
] | |
}; | |
Object.defineProperty(initialState, "userTasks", { | |
get: function userTasks() { | |
return this.users.map(user => | |
Object.assign({}, user, { | |
tasks: this.tasks.filter(task => task.assignee === user.id) | |
}) | |
); | |
}, | |
enumerable: false | |
}); | |
Object.defineProperty(initialState, "userTasksCount", { | |
get: function userTasksCount() { | |
return this.userTasks.map(user => | |
Object.assign({}, user, { tasksCount: user.tasks.count }) | |
); | |
}, | |
enumerable: false | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment