All files index.js

100% Statements 32/32
100% Branches 26/26
100% Functions 4/4
100% Lines 32/32

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 37 38 39 40 41 42 43 44 45 46 47 48 49 501x 1x 1x   1x 1x 3x 12x 7x 1x 6x 2x 2x 2x 4x 2x 3x 2x 2x 2x   1x     2x 1x 2x 1x   1x       1x     5x     3x     1x 1x 1x 1x        
const normalMerge = ['attrs', 'props', 'domProps']
const toArrayMerge = ['class', 'style', 'directives']
const functionalMerge = ['on', 'nativeOn']
 
const mergeJsxProps = objects =>
  objects.reduce((a, b) => {
    for (const key in b) {
      if (a[key]) {
        if (normalMerge.indexOf(key) !== -1) {
          a[key] = { ...a[key], ...b[key] }
        } else if (toArrayMerge.indexOf(key) !== -1) {
          const arrA = a[key] instanceof Array ? a[key] : [a[key]]
          const arrB = b[key] instanceof Array ? b[key] : [b[key]]
          a[key] = [...arrA, ...arrB]
        } else if (functionalMerge.indexOf(key) !== -1) {
          for (const event in b[key]) {
            if (a[key][event]) {
              const arrA = a[key][event] instanceof Array ? a[key][event] : [a[key][event]]
              const arrB = b[key][event] instanceof Array ? b[key][event] : [b[key][event]]
              a[key][event] = [...arrA, ...arrB]
            } else {
              a[key][event] = b[key][event]
            }
          }
        } else if (key === 'hook') {
          for (let hook in b[key]) {
            if (a[key][hook]) {
              a[key][hook] = mergeFn(a[key][hook], b[key][hook])
            } else {
              a[key][hook] = b[key][hook]
            }
          }
        } else {
          a[key] = b[key]
        }
      } else {
        a[key] = b[key]
      }
    }
    return a
  }, {})
 
const mergeFn = (fn1, fn2) =>
  function() {
    fn1 && fn1.apply(this, arguments)
    fn2 && fn2.apply(this, arguments)
  }
 
export default mergeJsxProps