Skip to content

Instantly share code, notes, and snippets.

@agoldis
Created April 18, 2018 06:32
Show Gist options
  • Save agoldis/125d758393697d50d5737fb23785659a to your computer and use it in GitHub Desktop.
Save agoldis/125d758393697d50d5737fb23785659a to your computer and use it in GitHub Desktop.
redux - hide getter
/* initialState.js */
const books = [ /* ... */ ]
const users = [ /* ... */ ]
const comments = [ /* ... */ ];
const usersSummary = function() {
return this.users.map(user => ({
...user,
booksCount: user.books.length,
commentsCount: this.comments.filter(c => c.user === user.id).length
}));
};
export const initialState = {
books,
users,
comments,
};
Object.defineProperty(initialState, "usersSummary", {
get: usersSummary,
enumerable: false
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment