This file contains 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
const deriveState = state => { | |
state.foo = "bar"; | |
return state; | |
} | |
const enhanceStore = createStore => (reducer, preloadedState, enhancer) => { | |
const store = createStore(reducer, preloadedState, enhancer); | |
const _originalGetState = store.getState; | |
store.getState = () => deriveState(_originalGetState()); | |
return store; |
This file contains 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 |
This file contains 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 |
This file contains 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
// Users list component mapper | |
const mapStateToProps = ({ users, comments }) => ({ | |
users: users.map(user => ({ | |
...user, | |
booksCount: user.books.length, | |
commentsCount: comments.filter(c => c.user === user.id).length | |
})) | |
}); | |
// Books list component mapper |
This file contains 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 { createSelector } from "reselect"; | |
const initialState = { | |
app: { | |
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" } | |
] |
This file contains 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
const initialState = { | |
app: { | |
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" } | |
] | |
}, | |
ui: { /* ... */ } |
This file contains 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 React from "react"; | |
import { connect } from "react-redux"; | |
const mapStateToProps = (({ userTasksCount }) => ({ userTasksCount })); | |
class Header extends React.Component { | |
render() { | |
const { userTasksCount } = this.props; | |
return <div> | |
{JSON.stringify(userTasksCount)} |
This file contains 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
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" } | |
], | |
profiles: [ | |
{ id: "profile01", user: "user01", picture: "picture01URL" }, | |
{ id: "profile02", user: "user02", picture: "picture02URL" } |
This file contains 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
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, { |