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
// ... | |
// initial state | |
const initialState = { | |
left: CounterPair.reducer(), | |
right: CounterPair.reducer(), | |
count: 0 | |
} | |
// listen to any action of subcomponents | |
const appReducer = createReducer( |
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 React from 'react' | |
import {connect, forwardTo, updateProperty, actionFor} from './core' | |
import * as Counter from './Counter' | |
// CONSTANTS | |
export const TOP = '@@TOP' | |
export const BOTTOM = '@@BOTTOM' | |
// ACTIONS | |
export const getTopState = state => state.top |
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 React from 'react' | |
import {connect, forwardTo, updateProperty, actionFor} from './core' | |
import * as Counter from './Counter' | |
// CONSTANTS | |
export const TOP = '@@TOP' | |
export const BOTTOM = '@@BOTTOM' | |
// ACTIONS | |
export const getTopState = state => state.top |
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
const FORWARD = '@redux-forward/FORWARD' | |
// wrap an action into a forward action | |
export const wrapTo = curry( | |
(name, action) => | |
({type: FORWARD, payload: action, meta: {name}}) | |
) | |
// unwrap recursively an action | |
export const unwrap = (action) => |
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
// ... | |
const reduxMapState = (state, props) => | |
mapStateToProps(props.selector(state), props, state) | |
const reduxMapDispatch = (dispatch, props) => | |
mapDispatchToProps(props.dispatch, props, dispatch) | |
const reduxMergeProps = (stateProps, dispatchProps, ownProps) => | |
({ ...stateProps, ...dispatchProps, ...ownProps }) |
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 {connect as reduxConnect} from 'react-redux' | |
export const connect = (mapStateToProps = defaultMapStateToProps, reduxMapDispatch, reduxMergeProps, options) => | |
BaseComponent => { | |
const reduxMapState = (state, props) => | |
mapStateToProps(props.selector(state), props, state) | |
const ReduxComponent = reduxConnect( | |
reduxMapState, |
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 {connect as reduxConnect} from 'react-redux' | |
export const connect = (mapStateToProps = defaultMapStateToProps, reduxMapDispatch, reduxMergeProps, options) => | |
BaseComponent => { | |
const reduxMapState = (state, props) => | |
mapStateToProps(props.selector(state), props, state) | |
const ReduxComponent = reduxConnect( | |
reduxMapState, |
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
const identity = state => state | |
const mergeSelectors = | |
(parentSelector, childSelector) => | |
state => | |
childSelector(parentSelector(state)) | |
const computeSelector = (props, ctx) => | |
mergeSelectors( |
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
export const getTopState = state => state.top | |
export const getBottomState = state => state.bottom |
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
export const view = connect()( | |
({name}) => <div> | |
<h3>{name}</h3> | |
<Counter.view name="Likes" selector={getTopState} /> | |
<Counter.view name="Hates" selector={getBottomState} /> | |
</div> | |
) |