github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/public/libs/vue-1.0.24/src/instance/internal/init.js (about)

     1  import { mergeOptions } from '../../util/index'
     2  
     3  let uid = 0
     4  
     5  export default function (Vue) {
     6    /**
     7     * The main init sequence. This is called for every
     8     * instance, including ones that are created from extended
     9     * constructors.
    10     *
    11     * @param {Object} options - this options object should be
    12     *                           the result of merging class
    13     *                           options and the options passed
    14     *                           in to the constructor.
    15     */
    16  
    17    Vue.prototype._init = function (options) {
    18      options = options || {}
    19  
    20      this.$el = null
    21      this.$parent = options.parent
    22      this.$root = this.$parent
    23        ? this.$parent.$root
    24        : this
    25      this.$children = []
    26      this.$refs = {}       // child vm references
    27      this.$els = {}        // element references
    28      this._watchers = []   // all watchers as an array
    29      this._directives = [] // all directives
    30  
    31      // a uid
    32      this._uid = uid++
    33  
    34      // a flag to avoid this being observed
    35      this._isVue = true
    36  
    37      // events bookkeeping
    38      this._events = {}            // registered callbacks
    39      this._eventsCount = {}       // for $broadcast optimization
    40  
    41      // fragment instance properties
    42      this._isFragment = false
    43      this._fragment =         // @type {DocumentFragment}
    44      this._fragmentStart =    // @type {Text|Comment}
    45      this._fragmentEnd = null // @type {Text|Comment}
    46  
    47      // lifecycle state
    48      this._isCompiled =
    49      this._isDestroyed =
    50      this._isReady =
    51      this._isAttached =
    52      this._isBeingDestroyed =
    53      this._vForRemoving = false
    54      this._unlinkFn = null
    55  
    56      // context:
    57      // if this is a transcluded component, context
    58      // will be the common parent vm of this instance
    59      // and its host.
    60      this._context = options._context || this.$parent
    61  
    62      // scope:
    63      // if this is inside an inline v-for, the scope
    64      // will be the intermediate scope created for this
    65      // repeat fragment. this is used for linking props
    66      // and container directives.
    67      this._scope = options._scope
    68  
    69      // fragment:
    70      // if this instance is compiled inside a Fragment, it
    71      // needs to reigster itself as a child of that fragment
    72      // for attach/detach to work properly.
    73      this._frag = options._frag
    74      if (this._frag) {
    75        this._frag.children.push(this)
    76      }
    77  
    78      // push self into parent / transclusion host
    79      if (this.$parent) {
    80        this.$parent.$children.push(this)
    81      }
    82  
    83      // merge options.
    84      options = this.$options = mergeOptions(
    85        this.constructor.options,
    86        options,
    87        this
    88      )
    89  
    90      // set ref
    91      this._updateRef()
    92  
    93      // initialize data as empty object.
    94      // it will be filled up in _initData().
    95      this._data = {}
    96  
    97      // call init hook
    98      this._callHook('init')
    99  
   100      // initialize data observation and scope inheritance.
   101      this._initState()
   102  
   103      // setup event system and option events.
   104      this._initEvents()
   105  
   106      // call created hook
   107      this._callHook('created')
   108  
   109      // if `el` option is passed, start compilation.
   110      if (options.el) {
   111        this.$mount(options.el)
   112      }
   113    }
   114  }