Created
April 18, 2018 06:32
-
-
Save agoldis/125d758393697d50d5737fb23785659a to your computer and use it in GitHub Desktop.
redux - hide getter
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
/* 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