Skip to content

Instantly share code, notes, and snippets.

View mattiamanzati's full-sized avatar
💭
undefined is not a function

Mattia Manzati mattiamanzati

💭
undefined is not a function
  • Effectful Technologies Inc
  • Ferrara, Italy
  • 03:41 (UTC +02:00)
  • X @mattiamanzati
View GitHub Profile
// ...
// initial state
const initialState = {
left: CounterPair.reducer(),
right: CounterPair.reducer(),
count: 0
}
// listen to any action of subcomponents
const appReducer = createReducer(
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
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
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) =>
// ...
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 })
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,
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,
const identity = state => state
const mergeSelectors =
(parentSelector, childSelector) =>
state =>
childSelector(parentSelector(state))
const computeSelector = (props, ctx) =>
mergeSelectors(
export const getTopState = state => state.top
export const getBottomState = state => state.bottom
export const view = connect()(
({name}) => <div>
<h3>{name}</h3>
<Counter.view name="Likes" selector={getTopState} />
<Counter.view name="Hates" selector={getBottomState} />
</div>
)