# All files / src/instance watch.ts

100% Statements 11/11
83.33% Branches 5/6
100% Functions 4/4
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
    1x
    1x

    2x
    11x
    10x

    1x
    1x
    1xexport function initWatch (vm, watch) {
      return Object.keys(watch).reduce((acc, key) => ({ ...acc, [key]: function defineWatch (newVal) {
        if (!this.$component || !this.$component._isMounted) { return }
        // Always equal to the newVal
        const oldVal = this.data[key]
        const handler = Array.isArray(watch[key]) ? watch[key] : [ watch[key] ]
        handler.forEach(h => {
          this[h.handler](newVal, oldVal)
        })
      } }), {})
    }