Skip to content

Instantly share code, notes, and snippets.

@agoldis
Created April 11, 2018 02:57
Show Gist options
  • Select an option

  • Save agoldis/c8f9c914a35e58c563364acfa1611a15 to your computer and use it in GitHub Desktop.

Select an option

Save agoldis/c8f9c914a35e58c563364acfa1611a15 to your computer and use it in GitHub Desktop.
redux blog
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" }
],
get userTasks() {
return this.users.map(user =>
Object.assign({}, user, {
tasks: this.tasks.filter(task => task.assignee === user.id)
})
);
},
get userTasksCount() {
return this.userTasks.map(user => Object.assign({}, user, { tasksCount: user.tasks.count })
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment