Evan You
9 years ago
7 changed files with 64 additions and 35 deletions
@ -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 |
|||
|
@ -0,0 +1,3 @@ |
|||
export function apiMixin (Vue) { |
|||
|
|||
} |
@ -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) |
|||
|
@ -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() |
|||
} |
|||
} |
Loading…
Reference in new issue