diff --git a/src/runtime/index.js b/src/runtime/index.js index d35513d3d..f92756ffa 100644 --- a/src/runtime/index.js +++ b/src/runtime/index.js @@ -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 diff --git a/src/runtime/instance/api.js b/src/runtime/instance/api.js new file mode 100644 index 000000000..20dea88c2 --- /dev/null +++ b/src/runtime/instance/api.js @@ -0,0 +1,3 @@ +export function apiMixin (Vue) { + +} diff --git a/src/runtime/instance/events.js b/src/runtime/instance/events.js new file mode 100644 index 000000000..24884112c --- /dev/null +++ b/src/runtime/instance/events.js @@ -0,0 +1,7 @@ +export function initEvents (vm) { + +} + +export function eventsMixin (Vue) { + +} diff --git a/src/runtime/instance/index.js b/src/runtime/instance/index.js index be823252e..6e5f7706c 100644 --- a/src/runtime/instance/index.js +++ b/src/runtime/instance/index.js @@ -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) diff --git a/src/runtime/instance/init.js b/src/runtime/instance/init.js deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/runtime/instance/render.js b/src/runtime/instance/render.js new file mode 100644 index 000000000..5ddba278c --- /dev/null +++ b/src/runtime/instance/render.js @@ -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() + } +} diff --git a/src/runtime/instance/state.js b/src/runtime/instance/state.js index 7e0df51e7..db246ce26 100644 --- a/src/runtime/instance/state.js +++ b/src/runtime/instance/state.js @@ -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