silk-gui
Version:
GUI for developers and Node OS
97 lines (78 loc) • 2.56 kB
JavaScript
var mergeOptions = require('../util/merge-option')
/**
* The main init sequence. This is called for every
* instance, including ones that are created from extended
* constructors.
*
* @param {Object} options - this options object should be
* the result of merging class
* options and the options passed
* in to the constructor.
*/
exports._init = function (options) {
options = options || {}
this.$el = null
this.$parent = options._parent
this.$root = options._root || this
this.$ = {} // child vm references
this.$$ = {} // element references
this._watcherList = [] // all watchers as an array
this._watchers = {} // internal watchers as a hash
this._userWatchers = {} // user watchers as a hash
this._directives = [] // all directives
// a flag to avoid this being observed
this._isVue = true
// events bookkeeping
this._events = {} // registered callbacks
this._eventsCount = {} // for $broadcast optimization
this._eventCancelled = false // for event cancellation
// block instance properties
this._isBlock = false
this._blockStart = // @type {CommentNode}
this._blockEnd = null // @type {CommentNode}
// lifecycle state
this._isCompiled =
this._isDestroyed =
this._isReady =
this._isAttached =
this._isBeingDestroyed = false
// children
this._children = []
this._childCtors = {}
// transclusion unlink functions
this._containerUnlinkFn =
this._contentUnlinkFn = null
// transcluded components that belong to the parent.
// need to keep track of them so that we can call
// attached/detached hooks on them.
this._transCpnts = []
this._host = options._host
// push self into parent / transclusion host
if (this.$parent) {
this.$parent._children.push(this)
}
if (this._host) {
this._host._transCpnts.push(this)
}
// props used in v-repeat diffing
this._new = true
this._reused = false
// merge options.
options = this.$options = mergeOptions(
this.constructor.options,
options,
this
)
// set data after merge.
this._data = options.data || {}
// initialize data observation and scope inheritance.
this._initScope()
// setup event system and option events.
this._initEvents()
// call created hook
this._callHook('created')
// if `el` option is passed, start compilation.
if (options.el) {
this.$mount(options.el)
}
}