All files / src scope.js

100% Statements 12/12
100% Branches 10/10
100% Functions 5/5
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  1x           1x 7x 7x 7x       7x       7x           2x   9x       1x  
 
import {
  isDefined,
  isFn,
  check
} from './utils'
 
const scopedUpdate = (predicate, update) => {
  const match = check(predicate)
  return (state, event) => {
    let type = typeof event === 'string' || isFn(predicate)
      ? event
      : event.type
 
    let checked = isFn(predicate)
      ? predicate(state, event)
      : match(type)
 
    return checked
      ? update(state, event)
      : state
  }
}
 
const createScope = predicate => update => scopedUpdate(predicate, update)
 
const scope = (predicate, update) => isDefined(update)
  ? scopedUpdate(predicate, update)
  : createScope(predicate)
 
export default scope