# All files / src/instance mixin.ts

86.2% Statements 25/29
25% Branches 2/8
55.55% Functions 5/9
92.59% Lines 25/27

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
    1x
    1x
    1x
    1x
    1x
    1x

    1x
    1x
    1x
    1x
    1x
    1x

    1x

    1x
    1x

    1x

    1x
    1x

    1x

    1x
    68x
    68x
    68x

    68x

    1x
     import { isDev } from '../util/env'
    import { nextTick } from '../util/nextTick'
    import { toArray } from '../util/toArray'
    import { warn } from '../util/warn'

    export function stateMixin (Component) {
      const dataDef: any = {}
      dataDef.get = function () { return this._renderProxy ? this._renderProxy.data : undefined }
      const propsDef: any = {}
      propsDef.get = function () { return this._renderProxy ? this._renderProxy.properties : undefined }
      if (isDev) {
        dataDef.set = function () {
        E  warn(
            'Avoid replacing instance root $data. ' +
            'Use nested data properties instead.',
            this
          )
        }
        propsDef.set = function () {
          warn('$props is readonly.', this)
        }
      }
      Object.defineProperty(Component.prototype, '$data', dataDef)
      Object.defineProperty(Component.prototype, '$props', propsDef)
    }

    export function renderMixin (Component) {
      Component.prototype.$nextTick = function (fn) {
        return nextTick(fn)
      }
    }

    export function eventsMixin (Component) {
      Component.prototype.$emit = function (event) {
        consEt args = toArray(arguments, 1)
        if (this._renderProxy) {
          this._renderProxy.triggerEvent(event, ...args)
        }
        return this
      }
    }