All files index.js

100% Statements 15/15
100% Branches 2/2
100% Functions 10/10
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36    1x               7x 1x 6x     7x   7x   7x   7x 7x       13x                  
import React from 'react'
 
const connect = (
  component,
  {
    initialState,
    reducer,
    createActions
  }
) => {
  const attach = (instance) => ({
    getState: () => instance.state,
    dispatch: createDispatcher(reducer, reducerCall => new Promise(resolve => instance.setState(reducerCall, resolve)))
  })
 
  const createDispatcher = (reducer, set) => (type, params) => set(state => reducer(state, Object.assign({ type }, params || {})))
 
  return class Connected extends React.Component {
    constructor (props) {
      super(props)
 
      this.state = Object.assign({}, initialState, props)
      this.actions = createActions(attach(this))
    }
 
    render () {
      return React.createElement(
        component,
        Object.assign({}, this.state, this.actions)
      )
    }
  }
}
 
export default connect