Skip to content

Instantly share code, notes, and snippets.

@agoldis
Created April 29, 2018 00:14
Show Gist options
  • Save agoldis/c104e458b8a81563a81b5e484e689bee to your computer and use it in GitHub Desktop.
Save agoldis/c104e458b8a81563a81b5e484e689bee to your computer and use it in GitHub Desktop.
redux - use state object
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