index.js 586 字节
Newer Older
Q
qiang 已提交
1
import { handleProps, markMPComponent } from './wrapper/util'
2 3 4 5 6 7

const MPComponent = Component

function initHook (name, options) {
  const oldHook = options[name]
  options[name] = function (...args) {
Q
qiang 已提交
8
    markMPComponent(this)
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
    const props = this.props
    if (props && props['data-com-type'] === 'wx') {
      handleProps(this)
    }
    if (oldHook) {
      return oldHook.apply(this, args)
    }
  }
}

if (!MPComponent.__$wrappered) {
  MPComponent.__$wrappered = true
  Component = function (options = {}) {
    initHook('onInit', options)
    return MPComponent(options)
  }
}