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
(function mediaQueryPolyfill() { | |
const mediaQueryAll = window.matchMedia('all'); | |
if (typeof mediaQueryAll.addEventListener == 'function') return | |
const defaultMatchMedia = window.matchMedia; | |
window.matchMedia = function (query) { | |
const mediaQuery = defaultMatchMedia(query); | |
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 fetchAccountsIfNeeded = () => (dispatch, getState) => { | |
if (shouldFetchAccounts(getState())) | |
return dispatch(fetchAccounts()) | |
} | |
const shouldFetchAccounts = ({ accounts }) => !accounts.fetching && !accounts.upToDate | |
const fetchAccounts = () => dispatch => { | |
dispatch(requestAccounts()) | |
return axios.get(`${apiHost}${accountsPath}`) |
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 mapStateToProps = (state) => ({ | |
accounts: state.accounts.items | |
}) | |
const mapDispatchToProps = (dispatch) => ({ | |
fetchAccounts: () => dispatch(fetchAccountsIfNeeded()) | |
}) | |
export default compose( | |
connect(mapStateToProps, mapDispatchToProps), |
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 compose = (f, g) => (x) => f(g(x)) |
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 mapStateToProps = (state) => ({ | |
accounts: state.accounts.items | |
}) | |
const mapDispatchToProps = (dispatch) => ({ | |
fetchAccounts: () => dispatch(fetchAccountsIfNeeded()) | |
}) | |
export default connect( | |
mapStateToProps, |
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 callOnMount = callback => WrappedComponent => class extends Component { | |
componentDidMount() { | |
callback(this.props) | |
} | |
render() { | |
return (<WrappedComponent {...this.props} />) | |
} | |
} |
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 BareComponent = () => <div>Hello</div> | |
export default enhancer(BareComponent) |
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
class AccountListContainer extends Component { | |
componentDidMount() { | |
this.props.fetchAccounts() | |
} | |
render() { | |
return (<AccountList {...this.props} />) | |
} | |
} |
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 AccountList = ({ accounts }) => (<ul> | |
{ | |
accounts.map(account => | |
<li key={account.id}>{account.name}</li> | |
) | |
} | |
</ul>) |
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 mapStateToProps = state => ({ | |
accounts: state.accounts.items | |
}) | |
const mapDispatchToProps = dispatch => ({ | |
fetchAccounts: () => dispatch(fetchAccountsIfNeeded()) | |
}) | |
export default connect(mapStateToProps, mapDispatchToProps)(AccountList) |
NewerOlder