Created
April 29, 2018 00:14
-
-
Save agoldis/c104e458b8a81563a81b5e484e689bee to your computer and use it in GitHub Desktop.
redux - use state object
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
import { | |
booksSummarySelector, | |
usersSummarySelector, | |
userDetailsSelector, | |
bookDetailsSelector | |
} from "./selectors"; | |
class NotRealState { | |
constructor(state) { | |
Object.defineProperty(this, "_state", { | |
value: state, | |
enumerable: false | |
}); | |
} | |
get state() { | |
return this._state; | |
} | |
get books() { | |
return this.state.books; | |
} | |
get users() { | |
return this.state.users; | |
} | |
get comments() { | |
return this.state.comments; | |
} | |
get booksSummary() { | |
return booksSummarySelector(this.state); | |
} | |
get usersSummary() { | |
return usersSummarySelector(this.state); | |
} | |
getUserDetails(userId) { | |
return userDetailsSelector(this.state, userId); | |
} | |
getBookDetails(bookId) { | |
return bookDetailsSelector(this.state, bookId); | |
} | |
} | |
export const deriveState = state => new NotRealState(state); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment