init.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. var Emitter = require('../emitter')
  2. var mergeOptions = require('../util/merge-option')
  3. /**
  4. * The main init sequence. This is called for every
  5. * instance, including ones that are created from extended
  6. * constructors.
  7. *
  8. * @param {Object} options - this options object should be
  9. * the result of merging class
  10. * options and the options passed
  11. * in to the constructor.
  12. */
  13. exports._init = function (options) {
  14. options = options || {}
  15. this.$el = null
  16. this.$ = {}
  17. this.$root = this.$root || this
  18. this._data = options.data || {}
  19. this._rawContent = null
  20. this._emitter = new Emitter(this)
  21. this._watchers = {}
  22. this._activeWatcher = null
  23. this._directives = []
  24. // block instance properties
  25. this._isBlock = false
  26. this._blockStart = null
  27. this._blockEnd = null
  28. // lifecycle state
  29. this._isCompiled = false
  30. this._isDestroyed = false
  31. this._isReady = false
  32. this._isAttached = false
  33. // anonymous instances are created by flow-control
  34. // directives such as v-if and v-repeat
  35. this._isAnonymous = options.anonymous
  36. // merge options.
  37. this.$options = mergeOptions(
  38. this.constructor.options,
  39. options,
  40. this
  41. )
  42. // the `created` hook is called after basic properties
  43. // have been set up & before data observation happens.
  44. this._callHook('created')
  45. // initialize data observation and scope inheritance
  46. this._initScope()
  47. // setup binding tree.
  48. // @creates this._rootBinding
  49. this._initBindings()
  50. // setup event system and option events
  51. this._initEvents()
  52. // if `el` option is passed, start compilation.
  53. if (options.el) {
  54. this.$mount(options.el)
  55. }
  56. }