mirror of
https://github.com/vuejs/vue.git
synced 2024-11-21 20:28:54 +00:00
restructure instance
This commit is contained in:
parent
91a04ad038
commit
b5800b274c
@ -1,5 +1,7 @@
|
||||
import Vue from './instance/index'
|
||||
import { nextTick } from './util/index'
|
||||
|
||||
Vue.nextTick = nextTick
|
||||
Vue.version = '2.0.0'
|
||||
|
||||
export default Vue
|
||||
|
3
src/runtime/instance/api.js
Normal file
3
src/runtime/instance/api.js
Normal file
@ -0,0 +1,3 @@
|
||||
export function apiMixin (Vue) {
|
||||
|
||||
}
|
7
src/runtime/instance/events.js
Normal file
7
src/runtime/instance/events.js
Normal file
@ -0,0 +1,7 @@
|
||||
export function initEvents (vm) {
|
||||
|
||||
}
|
||||
|
||||
export function eventsMixin (Vue) {
|
||||
|
||||
}
|
@ -1,41 +1,17 @@
|
||||
import Watcher from '../observer/watcher'
|
||||
import { h, patch } from '../vdom/index'
|
||||
import { nextTick, query } from '../util/index'
|
||||
import { initState, setData } from './state'
|
||||
import { initState, stateMixin } from './state'
|
||||
import { initRender, renderMixin } from './render'
|
||||
import { initEvents, eventsMixin } from './events'
|
||||
import { apiMixin } from './api'
|
||||
|
||||
export default function Vue (options) {
|
||||
this.$options = options
|
||||
this._watchers = []
|
||||
initState(this)
|
||||
this._el = query(options.el)
|
||||
this._el.innerHTML = ''
|
||||
this._watcher = new Watcher(this, options.render, this._update)
|
||||
this._update(this._watcher.value)
|
||||
initEvents(this)
|
||||
initRender(this)
|
||||
}
|
||||
|
||||
Vue.prototype._update = function (vtree) {
|
||||
if (!this._tree) {
|
||||
patch(this._el, vtree)
|
||||
} else {
|
||||
patch(this._tree, vtree)
|
||||
}
|
||||
this._tree = vtree
|
||||
}
|
||||
|
||||
Vue.prototype.$forceUpdate = function () {
|
||||
this._watcher.run()
|
||||
}
|
||||
|
||||
Object.defineProperty(Vue.prototype, '$data', {
|
||||
get () {
|
||||
return this._data
|
||||
},
|
||||
set (newData) {
|
||||
if (newData !== this._data) {
|
||||
setData(this, newData)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Vue.prototype.__h__ = h
|
||||
Vue.nextTick = nextTick
|
||||
stateMixin(Vue)
|
||||
eventsMixin(Vue)
|
||||
renderMixin(Vue)
|
||||
apiMixin(Vue)
|
||||
|
28
src/runtime/instance/render.js
Normal file
28
src/runtime/instance/render.js
Normal file
@ -0,0 +1,28 @@
|
||||
import Watcher from '../observer/watcher'
|
||||
import { query } from '../util/index'
|
||||
import { h, patch } from '../vdom/index'
|
||||
|
||||
export function initRender (vm) {
|
||||
const options = vm.$options
|
||||
vm._el = query(options.el)
|
||||
vm._el.innerHTML = ''
|
||||
vm._watcher = new Watcher(vm, options.render, vm._update)
|
||||
vm._update(vm._watcher.value)
|
||||
}
|
||||
|
||||
export function renderMixin (Vue) {
|
||||
Vue.prototype.__h__ = h
|
||||
|
||||
Vue.prototype._update = function (vtree) {
|
||||
if (!this._tree) {
|
||||
patch(this._el, vtree)
|
||||
} else {
|
||||
patch(this._tree, vtree)
|
||||
}
|
||||
this._tree = vtree
|
||||
}
|
||||
|
||||
Vue.prototype.$forceUpdate = function () {
|
||||
this._watcher.run()
|
||||
}
|
||||
}
|
@ -112,7 +112,20 @@ function unproxy (vm, key) {
|
||||
}
|
||||
}
|
||||
|
||||
export function setData (vm, newData) {
|
||||
export function stateMixin (Vue) {
|
||||
Object.defineProperty(Vue.prototype, '$data', {
|
||||
get () {
|
||||
return this._data
|
||||
},
|
||||
set (newData) {
|
||||
if (newData !== this._data) {
|
||||
setData(this, newData)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function setData (vm, newData) {
|
||||
newData = newData || {}
|
||||
var oldData = vm._data
|
||||
vm._data = newData
|
||||
|
Loading…
Reference in New Issue
Block a user