vue.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. var _ = require('./util')
  2. var extend = _.extend
  3. /**
  4. * The exposed Vue constructor.
  5. *
  6. * API conventions:
  7. * - public API methods/properties are prefiexed with `$`
  8. * - internal methods/properties are prefixed with `_`
  9. * - non-prefixed properties are assumed to be proxied user
  10. * data.
  11. *
  12. * @constructor
  13. * @param {Object} [options]
  14. * @public
  15. */
  16. function Vue (options) {
  17. this._init(options)
  18. }
  19. /**
  20. * Mixin global API
  21. */
  22. extend(Vue, require('./api/global'))
  23. /**
  24. * Vue and every constructor that extends Vue has an
  25. * associated options object, which can be accessed during
  26. * compilation steps as `this.constructor.options`.
  27. *
  28. * These can be seen as the default options of every
  29. * Vue instance.
  30. */
  31. Vue.options = {
  32. replace: true,
  33. directives: require('./directives/public'),
  34. elementDirectives: require('./directives/element'),
  35. filters: require('./filters'),
  36. transitions: {},
  37. components: {},
  38. partials: {}
  39. }
  40. /**
  41. * Build up the prototype
  42. */
  43. var p = Vue.prototype
  44. /**
  45. * $data has a setter which does a bunch of
  46. * teardown/setup work
  47. */
  48. Object.defineProperty(p, '$data', {
  49. get: function () {
  50. return this._data
  51. },
  52. set: function (newData) {
  53. if (newData !== this._data) {
  54. this._setData(newData)
  55. }
  56. }
  57. })
  58. /**
  59. * Mixin internal instance methods
  60. */
  61. extend(p, require('./instance/init'))
  62. extend(p, require('./instance/events'))
  63. extend(p, require('./instance/state'))
  64. extend(p, require('./instance/lifecycle'))
  65. extend(p, require('./instance/misc'))
  66. /**
  67. * Mixin public API methods
  68. */
  69. extend(p, require('./api/data'))
  70. extend(p, require('./api/dom'))
  71. extend(p, require('./api/events'))
  72. extend(p, require('./api/child'))
  73. extend(p, require('./api/lifecycle'))
  74. Vue.version = '1.0.0-alpha'
  75. module.exports = _.Vue = Vue