All files / src createAdaptor.js

100% Statements 14/14
100% Branches 8/8
100% Functions 6/6
100% Lines 12/12

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  2x   1x 2x 11x 11x 11x   11x 11x 2x         9x 9x                 9x        
 
const identity = _ => _
 
export const createAdaptor = (cb) => {
  return function adaptor (signal) {
    let internalState = {}
    signal.observe(state => {
      internalState = state
    })
    return function connect (selector, fn) {
      if (fn && !selector) {
        throw new Error('No state selector for connected function')
      }
 
      // selector is optional, if it is omitted then assume the first
      // argument is the component function
      const select = fn ? selector : identity
      const func = fn || selector
 
      // return props => {
      //   let state = select(internalState)
      //   return func(state, props)
      // }
 
      // return cb(select, internalState, func)
 
      return cb(select, () => internalState, func)
    }
  }
}