mirror of
https://gitee.com/vuejs/vue.git
synced 2024-12-04 21:17:55 +08:00
use classes
This commit is contained in:
parent
be2e79df27
commit
96f02660a2
@ -14,7 +14,6 @@ import { generate } from './codegen'
|
||||
* - getTagNamespace
|
||||
* - delimiters
|
||||
*/
|
||||
|
||||
export function compile (template, options) {
|
||||
const ast = parse(template.trim(), options)
|
||||
optimize(ast, options)
|
||||
|
@ -13,7 +13,6 @@ let isPlatformReservedTag
|
||||
* create fresh nodes for them on each re-render;
|
||||
* 2. Completely skip them in the patching process.
|
||||
*/
|
||||
|
||||
export function optimize (root, options) {
|
||||
isPlatformReservedTag = options.isReservedTag || (() => false)
|
||||
// first pass: mark all non-static nodes.
|
||||
|
@ -37,7 +37,6 @@ let delimiters
|
||||
* @param {Object} options
|
||||
* @return {Object}
|
||||
*/
|
||||
|
||||
export function parse (template, options) {
|
||||
warn = options.warn || baseWarn
|
||||
platformGetTagNamespace = options.getTagNamespace || (() => null)
|
||||
|
@ -3,7 +3,6 @@ export default {
|
||||
/**
|
||||
* Preserve whitespaces between elements.
|
||||
*/
|
||||
|
||||
preserveWhitespace: true,
|
||||
|
||||
/**
|
||||
@ -11,21 +10,18 @@ export default {
|
||||
*
|
||||
* @type {Boolean}
|
||||
*/
|
||||
|
||||
silent: false,
|
||||
|
||||
/**
|
||||
* Check if a tag is reserved so that it cannot be registered as a
|
||||
* component. This is platform-dependent and may be overwritten.
|
||||
*/
|
||||
|
||||
isReservedTag: () => false,
|
||||
|
||||
/**
|
||||
* Check if a tag is an unknown element.
|
||||
* Platform-dependent.
|
||||
*/
|
||||
|
||||
isUnknownElement: () => false,
|
||||
|
||||
/**
|
||||
@ -33,7 +29,6 @@ export default {
|
||||
*
|
||||
* @type {Array}
|
||||
*/
|
||||
|
||||
_assetTypes: [
|
||||
'component',
|
||||
'directive',
|
||||
@ -46,7 +41,6 @@ export default {
|
||||
*
|
||||
* @type {Array}
|
||||
*/
|
||||
|
||||
_lifecycleHooks: [
|
||||
'init',
|
||||
'created',
|
||||
@ -62,6 +56,5 @@ export default {
|
||||
/**
|
||||
* Max circular updates allowed in a batcher flush cycle.
|
||||
*/
|
||||
|
||||
_maxUpdateCount: 100
|
||||
}
|
||||
|
@ -3,13 +3,12 @@ import { warn, isPlainObject } from '../util/index'
|
||||
|
||||
export function initAssetRegisters (Vue) {
|
||||
/**
|
||||
* Create asset registration methods with the following
|
||||
* signature:
|
||||
*
|
||||
* @param {String} id
|
||||
* @param {*} definition
|
||||
*/
|
||||
|
||||
* Create asset registration methods with the following
|
||||
* signature:
|
||||
*
|
||||
* @param {String} id
|
||||
* @param {*} definition
|
||||
*/
|
||||
config._assetTypes.forEach(function (type) {
|
||||
Vue[type] = function (id, definition) {
|
||||
if (!definition) {
|
||||
|
@ -7,7 +7,6 @@ export function initExtend (Vue) {
|
||||
* cid. This enables us to create wrapped "child
|
||||
* constructors" for prototypal inheritance and cache them.
|
||||
*/
|
||||
|
||||
Vue.cid = 0
|
||||
let cid = 1
|
||||
|
||||
@ -16,7 +15,6 @@ export function initExtend (Vue) {
|
||||
*
|
||||
* @param {Object} extendOptions
|
||||
*/
|
||||
|
||||
Vue.extend = function (extendOptions) {
|
||||
extendOptions = extendOptions || {}
|
||||
const Super = this
|
||||
|
@ -6,7 +6,6 @@ export function initUse (Vue) {
|
||||
*
|
||||
* @param {Object} plugin
|
||||
*/
|
||||
|
||||
Vue.use = function (plugin) {
|
||||
/* istanbul ignore if */
|
||||
if (plugin.installed) {
|
||||
|
@ -26,7 +26,6 @@ export function eventsMixin (Vue) {
|
||||
* @param {String} event
|
||||
* @param {Function} fn
|
||||
*/
|
||||
|
||||
Vue.prototype.$once = function (event, fn) {
|
||||
const self = this
|
||||
function on () {
|
||||
@ -45,7 +44,6 @@ export function eventsMixin (Vue) {
|
||||
* @param {String} event
|
||||
* @param {Function} fn
|
||||
*/
|
||||
|
||||
Vue.prototype.$off = function (event, fn) {
|
||||
// all
|
||||
if (!arguments.length) {
|
||||
@ -79,7 +77,6 @@ export function eventsMixin (Vue) {
|
||||
*
|
||||
* @param {String} event
|
||||
*/
|
||||
|
||||
Vue.prototype.$emit = function (event) {
|
||||
let cbs = this._events[event]
|
||||
if (cbs) {
|
||||
|
@ -3,40 +3,38 @@ import { initState, stateMixin } from './state'
|
||||
import { initRender, renderMixin } from './render'
|
||||
import { initEvents, eventsMixin } from './events'
|
||||
import { initLifecycle, lifecycleMixin, callHook } from './lifecycle'
|
||||
import { nextTick, mergeOptions } from '../util/index'
|
||||
import { mergeOptions } from '../util/index'
|
||||
|
||||
let uid = 0
|
||||
|
||||
export default function Vue (options) {
|
||||
this._init(options)
|
||||
}
|
||||
|
||||
Vue.prototype._init = function (options) {
|
||||
// a uid
|
||||
this._uid = uid++
|
||||
// a flag to avoid this being observed
|
||||
this._isVue = true
|
||||
// merge options
|
||||
this.$options = mergeOptions(
|
||||
this.constructor.options,
|
||||
options || {},
|
||||
this
|
||||
)
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
initProxy(this)
|
||||
} else {
|
||||
this._renderProxy = this
|
||||
export default class Vue {
|
||||
constructor (options) {
|
||||
this._init(options)
|
||||
}
|
||||
initLifecycle(this)
|
||||
initEvents(this)
|
||||
callHook(this, 'init')
|
||||
initState(this)
|
||||
callHook(this, 'created')
|
||||
initRender(this)
|
||||
}
|
||||
|
||||
Vue.prototype.$nextTick = function (fn) {
|
||||
nextTick(fn, this)
|
||||
_init (options) {
|
||||
// a uid
|
||||
this._uid = uid++
|
||||
// a flag to avoid this being observed
|
||||
this._isVue = true
|
||||
// merge options
|
||||
this.$options = mergeOptions(
|
||||
this.constructor.options,
|
||||
options || {},
|
||||
this
|
||||
)
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
initProxy(this)
|
||||
} else {
|
||||
this._renderProxy = this
|
||||
}
|
||||
initLifecycle(this)
|
||||
initEvents(this)
|
||||
callHook(this, 'init')
|
||||
initState(this)
|
||||
callHook(this, 'created')
|
||||
initRender(this)
|
||||
}
|
||||
}
|
||||
|
||||
stateMixin(Vue)
|
||||
|
@ -1,7 +1,7 @@
|
||||
import createElement from '../vdom/create-element'
|
||||
import { flatten } from '../vdom/helpers'
|
||||
import { bind, isArray, isObject, renderString } from 'shared/util'
|
||||
import { resolveAsset } from '../util/options'
|
||||
import { resolveAsset, nextTick } from '../util/index'
|
||||
|
||||
export const renderState = {
|
||||
activeInstance: null
|
||||
@ -21,6 +21,10 @@ export function initRender (vm) {
|
||||
}
|
||||
|
||||
export function renderMixin (Vue) {
|
||||
Vue.prototype.$nextTick = function (fn) {
|
||||
nextTick(fn, this)
|
||||
}
|
||||
|
||||
Vue.prototype._render = function () {
|
||||
const prev = renderState.activeInstance
|
||||
renderState.activeInstance = this
|
||||
|
@ -6,7 +6,6 @@ export const arrayMethods = Object.create(arrayProto)
|
||||
/**
|
||||
* Intercept mutating methods and emit events
|
||||
*/
|
||||
|
||||
;[
|
||||
'push',
|
||||
'pop',
|
||||
|
@ -20,7 +20,6 @@ let waiting = false
|
||||
/**
|
||||
* Reset the batcher's state.
|
||||
*/
|
||||
|
||||
function resetBatcherState () {
|
||||
queue.length = 0
|
||||
userQueue.length = 0
|
||||
@ -34,7 +33,6 @@ function resetBatcherState () {
|
||||
/**
|
||||
* Flush both queues and run the watchers.
|
||||
*/
|
||||
|
||||
function flushBatcherQueue () {
|
||||
runBatcherQueue(queue.sort(queueSorter))
|
||||
queue.length = 0
|
||||
@ -53,7 +51,6 @@ function flushBatcherQueue () {
|
||||
* pushed into the queue first and then its parent's props
|
||||
* changed.
|
||||
*/
|
||||
|
||||
function queueSorter (a, b) {
|
||||
return a.id - b.id
|
||||
}
|
||||
@ -63,7 +60,6 @@ function queueSorter (a, b) {
|
||||
*
|
||||
* @param {Array} queue
|
||||
*/
|
||||
|
||||
function runBatcherQueue (queue) {
|
||||
// do not cache length because more watchers might be pushed
|
||||
// as we run existing watchers
|
||||
@ -97,7 +93,6 @@ function runBatcherQueue (queue) {
|
||||
* - {Number} id
|
||||
* - {Function} run
|
||||
*/
|
||||
|
||||
export function pushWatcher (watcher) {
|
||||
const id = watcher.id
|
||||
if (has[id] == null) {
|
||||
|
@ -8,53 +8,34 @@ let uid = 0
|
||||
*
|
||||
* @constructor
|
||||
*/
|
||||
export default class Dep {
|
||||
constructor () {
|
||||
this.id = uid++
|
||||
this.subs = []
|
||||
}
|
||||
|
||||
export default function Dep () {
|
||||
this.id = uid++
|
||||
this.subs = []
|
||||
addSub (sub) {
|
||||
this.subs.push(sub)
|
||||
}
|
||||
|
||||
removeSub (sub) {
|
||||
remove(this.subs, sub)
|
||||
}
|
||||
|
||||
depend () {
|
||||
Dep.target.addDep(this)
|
||||
}
|
||||
|
||||
notify () {
|
||||
// stablize the subscriber list first
|
||||
const subs = this.subs.slice()
|
||||
for (let i = 0, l = subs.length; i < l; i++) {
|
||||
subs[i].update()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// the current target watcher being evaluated.
|
||||
// this is globally unique because there could be only one
|
||||
// watcher being evaluated at any time.
|
||||
Dep.target = null
|
||||
|
||||
/**
|
||||
* Add a directive subscriber.
|
||||
*
|
||||
* @param {Directive} sub
|
||||
*/
|
||||
|
||||
Dep.prototype.addSub = function (sub) {
|
||||
this.subs.push(sub)
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a directive subscriber.
|
||||
*
|
||||
* @param {Directive} sub
|
||||
*/
|
||||
|
||||
Dep.prototype.removeSub = function (sub) {
|
||||
remove(this.subs, sub)
|
||||
}
|
||||
|
||||
/**
|
||||
* Add self as a dependency to the target watcher.
|
||||
*/
|
||||
|
||||
Dep.prototype.depend = function () {
|
||||
Dep.target.addDep(this)
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify all subscribers of a new value.
|
||||
*/
|
||||
|
||||
Dep.prototype.notify = function () {
|
||||
// stablize the subscriber list first
|
||||
const subs = this.subs.slice()
|
||||
for (let i = 0, l = subs.length; i < l; i++) {
|
||||
subs[i].update()
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,6 @@ const arrayKeys = Object.getOwnPropertyNames(arrayMethods)
|
||||
* we don't want to force conversion because the value may be a nested value
|
||||
* under a frozen data structure. Converting it would defeat the optimization.
|
||||
*/
|
||||
|
||||
export const observerState = {
|
||||
shouldConvert: true
|
||||
}
|
||||
@ -33,84 +32,69 @@ export const observerState = {
|
||||
* @param {Array|Object} value
|
||||
* @constructor
|
||||
*/
|
||||
|
||||
export function Observer (value) {
|
||||
this.value = value
|
||||
this.dep = new Dep()
|
||||
def(value, '__ob__', this)
|
||||
if (isArray(value)) {
|
||||
const augment = hasProto
|
||||
? protoAugment
|
||||
: copyAugment
|
||||
augment(value, arrayMethods, arrayKeys)
|
||||
this.observeArray(value)
|
||||
} else {
|
||||
this.walk(value)
|
||||
export class Observer {
|
||||
constructor (value) {
|
||||
this.value = value
|
||||
this.dep = new Dep()
|
||||
this.vms = null
|
||||
def(value, '__ob__', this)
|
||||
if (isArray(value)) {
|
||||
const augment = hasProto
|
||||
? protoAugment
|
||||
: copyAugment
|
||||
augment(value, arrayMethods, arrayKeys)
|
||||
this.observeArray(value)
|
||||
} else {
|
||||
this.walk(value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Instance methods
|
||||
|
||||
/**
|
||||
* Walk through each property and convert them into
|
||||
* getter/setters. This method should only be called when
|
||||
* value type is Object.
|
||||
*
|
||||
* @param {Object} obj
|
||||
*/
|
||||
|
||||
Observer.prototype.walk = function (obj) {
|
||||
for (const key in obj) {
|
||||
this.convert(key, obj[key])
|
||||
/**
|
||||
* Walk through each property and convert them into
|
||||
* getter/setters. This method should only be called when
|
||||
* value type is Object.
|
||||
*
|
||||
* @param {Object} obj
|
||||
*/
|
||||
walk (obj) {
|
||||
const val = this.value
|
||||
for (const key in obj) {
|
||||
defineReactive(val, key, obj[key])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Observe a list of Array items.
|
||||
*
|
||||
* @param {Array} items
|
||||
*/
|
||||
|
||||
Observer.prototype.observeArray = function (items) {
|
||||
for (let i = 0, l = items.length; i < l; i++) {
|
||||
observe(items[i])
|
||||
/**
|
||||
* Observe a list of Array items.
|
||||
*
|
||||
* @param {Array} items
|
||||
*/
|
||||
observeArray (items) {
|
||||
for (let i = 0, l = items.length; i < l; i++) {
|
||||
observe(items[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a property into getter/setter so we can emit
|
||||
* the events when the property is accessed/changed.
|
||||
*
|
||||
* @param {String} key
|
||||
* @param {*} val
|
||||
*/
|
||||
/**
|
||||
* Add an owner vm, so that when $set/$delete mutations
|
||||
* happen we can notify owner vms to proxy the keys and
|
||||
* digest the watchers. This is only called when the object
|
||||
* is observed as an instance's root $data.
|
||||
*
|
||||
* @param {Vue} vm
|
||||
*/
|
||||
addVm (vm) {
|
||||
(this.vms || (this.vms = [])).push(vm)
|
||||
}
|
||||
|
||||
Observer.prototype.convert = function (key, val) {
|
||||
defineReactive(this.value, key, val)
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an owner vm, so that when $set/$delete mutations
|
||||
* happen we can notify owner vms to proxy the keys and
|
||||
* digest the watchers. This is only called when the object
|
||||
* is observed as an instance's root $data.
|
||||
*
|
||||
* @param {Vue} vm
|
||||
*/
|
||||
|
||||
Observer.prototype.addVm = function (vm) {
|
||||
(this.vms || (this.vms = [])).push(vm)
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove an owner vm. This is called when the object is
|
||||
* swapped out as an instance's $data object.
|
||||
*
|
||||
* @param {Vue} vm
|
||||
*/
|
||||
|
||||
Observer.prototype.removeVm = function (vm) {
|
||||
remove(this.vms, vm)
|
||||
/**
|
||||
* Remove an owner vm. This is called when the object is
|
||||
* swapped out as an instance's $data object.
|
||||
*
|
||||
* @param {Vue} vm
|
||||
*/
|
||||
removeVm (vm) {
|
||||
remove(this.vms, vm)
|
||||
}
|
||||
}
|
||||
|
||||
// helpers
|
||||
@ -122,7 +106,6 @@ Observer.prototype.removeVm = function (vm) {
|
||||
* @param {Object|Array} target
|
||||
* @param {Object} src
|
||||
*/
|
||||
|
||||
function protoAugment (target, src) {
|
||||
/* eslint-disable no-proto */
|
||||
target.__proto__ = src
|
||||
@ -136,7 +119,6 @@ function protoAugment (target, src) {
|
||||
* @param {Object|Array} target
|
||||
* @param {Object} proto
|
||||
*/
|
||||
|
||||
function copyAugment (target, src, keys) {
|
||||
for (let i = 0, l = keys.length; i < l; i++) {
|
||||
const key = keys[i]
|
||||
@ -154,7 +136,6 @@ function copyAugment (target, src, keys) {
|
||||
* @return {Observer|undefined}
|
||||
* @static
|
||||
*/
|
||||
|
||||
export function observe (value, vm) {
|
||||
if (!isObject(value)) {
|
||||
return
|
||||
@ -183,7 +164,6 @@ export function observe (value, vm) {
|
||||
* @param {String} key
|
||||
* @param {*} val
|
||||
*/
|
||||
|
||||
export function defineReactive (obj, key, val) {
|
||||
const dep = new Dep()
|
||||
|
||||
@ -242,7 +222,6 @@ export function defineReactive (obj, key, val) {
|
||||
* @param {*} val
|
||||
* @public
|
||||
*/
|
||||
|
||||
export function set (obj, key, val) {
|
||||
if (isArray(obj)) {
|
||||
return obj.splice(key, 1, val)
|
||||
@ -260,7 +239,7 @@ export function set (obj, key, val) {
|
||||
obj[key] = val
|
||||
return
|
||||
}
|
||||
ob.convert(key, val)
|
||||
defineReactive(ob.value, key, val)
|
||||
ob.dep.notify()
|
||||
if (ob.vms) {
|
||||
let i = ob.vms.length
|
||||
@ -279,7 +258,6 @@ export function set (obj, key, val) {
|
||||
* @param {Object} obj
|
||||
* @param {String} key
|
||||
*/
|
||||
|
||||
export function del (obj, key) {
|
||||
if (!hasOwn(obj, key)) {
|
||||
return
|
||||
|
@ -32,206 +32,184 @@ let prevTarget
|
||||
* - {Function} [postProcess]
|
||||
* @constructor
|
||||
*/
|
||||
|
||||
export default function Watcher (vm, expOrFn, cb, options) {
|
||||
// mix in options
|
||||
if (options) {
|
||||
extend(this, options)
|
||||
export default class Watcher {
|
||||
constructor (vm, expOrFn, cb, options) {
|
||||
// mix in options
|
||||
if (options) {
|
||||
extend(this, options)
|
||||
}
|
||||
const isFn = typeof expOrFn === 'function'
|
||||
this.vm = vm
|
||||
vm._watchers.push(this)
|
||||
this.expression = expOrFn
|
||||
this.cb = cb
|
||||
this.id = ++uid // uid for batching
|
||||
this.active = true
|
||||
this.dirty = this.lazy // for lazy watchers
|
||||
this.deps = []
|
||||
this.newDeps = []
|
||||
this.depIds = new Set()
|
||||
this.newDepIds = new Set()
|
||||
// parse expression for getter
|
||||
if (isFn) {
|
||||
this.getter = expOrFn
|
||||
} else {
|
||||
this.getter = parsePath(expOrFn)
|
||||
if (!this.getter) {
|
||||
this.getter = function () {}
|
||||
process.env.NODE_ENV !== 'production' && warn(
|
||||
'Failed watching path: ' + expOrFn +
|
||||
'Watcher only accepts simple dot-delimited paths. ' +
|
||||
'For full control, use a function instead.',
|
||||
vm
|
||||
)
|
||||
}
|
||||
}
|
||||
this.value = this.lazy
|
||||
? undefined
|
||||
: this.get()
|
||||
}
|
||||
const isFn = typeof expOrFn === 'function'
|
||||
this.vm = vm
|
||||
vm._watchers.push(this)
|
||||
this.expression = expOrFn
|
||||
this.cb = cb
|
||||
this.id = ++uid // uid for batching
|
||||
this.active = true
|
||||
this.dirty = this.lazy // for lazy watchers
|
||||
this.deps = []
|
||||
this.newDeps = []
|
||||
this.depIds = new Set()
|
||||
this.newDepIds = new Set()
|
||||
// parse expression for getter
|
||||
if (isFn) {
|
||||
this.getter = expOrFn
|
||||
} else {
|
||||
this.getter = parsePath(expOrFn)
|
||||
if (!this.getter) {
|
||||
this.getter = function () {}
|
||||
process.env.NODE_ENV !== 'production' && warn(
|
||||
'Failed watching path: ' + expOrFn +
|
||||
'Watcher only accepts simple dot-delimited paths. ' +
|
||||
'For full control, use a function instead.',
|
||||
vm
|
||||
)
|
||||
|
||||
/**
|
||||
* Evaluate the getter, and re-collect dependencies.
|
||||
*/
|
||||
get () {
|
||||
this.beforeGet()
|
||||
const value = this.getter.call(this.vm, this.vm)
|
||||
// "touch" every property so they are all tracked as
|
||||
// dependencies for deep watching
|
||||
if (this.deep) {
|
||||
traverse(value)
|
||||
}
|
||||
this.afterGet()
|
||||
return value
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare for dependency collection.
|
||||
*/
|
||||
beforeGet () {
|
||||
prevTarget = Dep.target
|
||||
Dep.target = this
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a dependency to this directive.
|
||||
*
|
||||
* @param {Dep} dep
|
||||
*/
|
||||
addDep (dep) {
|
||||
const id = dep.id
|
||||
if (!this.newDepIds.has(id)) {
|
||||
this.newDepIds.add(id)
|
||||
this.newDeps.push(dep)
|
||||
if (!this.depIds.has(id)) {
|
||||
dep.addSub(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
this.value = this.lazy
|
||||
? undefined
|
||||
: this.get()
|
||||
// state for avoiding false triggers for deep and Array
|
||||
// watchers during vm._digest()
|
||||
this.queued = this.shallow = false
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluate the getter, and re-collect dependencies.
|
||||
*/
|
||||
|
||||
Watcher.prototype.get = function () {
|
||||
this.beforeGet()
|
||||
const value = this.getter.call(this.vm, this.vm)
|
||||
// "touch" every property so they are all tracked as
|
||||
// dependencies for deep watching
|
||||
if (this.deep) {
|
||||
traverse(value)
|
||||
}
|
||||
this.afterGet()
|
||||
return value
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare for dependency collection.
|
||||
*/
|
||||
|
||||
Watcher.prototype.beforeGet = function () {
|
||||
prevTarget = Dep.target
|
||||
Dep.target = this
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a dependency to this directive.
|
||||
*
|
||||
* @param {Dep} dep
|
||||
*/
|
||||
|
||||
Watcher.prototype.addDep = function (dep) {
|
||||
const id = dep.id
|
||||
if (!this.newDepIds.has(id)) {
|
||||
this.newDepIds.add(id)
|
||||
this.newDeps.push(dep)
|
||||
if (!this.depIds.has(id)) {
|
||||
dep.addSub(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up for dependency collection.
|
||||
*/
|
||||
|
||||
Watcher.prototype.afterGet = function () {
|
||||
Dep.target = prevTarget
|
||||
let i = this.deps.length
|
||||
while (i--) {
|
||||
const dep = this.deps[i]
|
||||
if (!this.newDepIds.has(dep.id)) {
|
||||
dep.removeSub(this)
|
||||
}
|
||||
}
|
||||
let tmp = this.depIds
|
||||
this.depIds = this.newDepIds
|
||||
this.newDepIds = tmp
|
||||
this.newDepIds.clear()
|
||||
tmp = this.deps
|
||||
this.deps = this.newDeps
|
||||
this.newDeps = tmp
|
||||
this.newDeps.length = 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscriber interface.
|
||||
* Will be called when a dependency changes.
|
||||
*
|
||||
* @param {Boolean} shallow
|
||||
*/
|
||||
|
||||
Watcher.prototype.update = function (shallow) {
|
||||
if (this.lazy) {
|
||||
this.dirty = true
|
||||
} else if (this.sync) {
|
||||
this.run()
|
||||
} else {
|
||||
// if queued, only overwrite shallow with non-shallow,
|
||||
// but not the other way around.
|
||||
this.shallow = this.queued
|
||||
? shallow
|
||||
? this.shallow
|
||||
: false
|
||||
: !!shallow
|
||||
this.queued = true
|
||||
pushWatcher(this)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Batcher job interface.
|
||||
* Will be called by the batcher.
|
||||
*/
|
||||
|
||||
Watcher.prototype.run = function () {
|
||||
if (this.active) {
|
||||
const value = this.get()
|
||||
if (
|
||||
value !== this.value ||
|
||||
// Deep watchers and watchers on Object/Arrays should fire even
|
||||
// when the value is the same, because the value may
|
||||
// have mutated; but only do so if this is a
|
||||
// non-shallow update (caused by a vm digest).
|
||||
((isObject(value) || this.deep) && !this.shallow)
|
||||
) {
|
||||
// set new value
|
||||
const oldValue = this.value
|
||||
this.value = value
|
||||
this.cb.call(this.vm, value, oldValue)
|
||||
}
|
||||
this.queued = this.shallow = false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluate the value of the watcher.
|
||||
* This only gets called for lazy watchers.
|
||||
*/
|
||||
|
||||
Watcher.prototype.evaluate = function () {
|
||||
// avoid overwriting another watcher that is being
|
||||
// collected.
|
||||
const current = Dep.target
|
||||
this.value = this.get()
|
||||
this.dirty = false
|
||||
Dep.target = current
|
||||
}
|
||||
|
||||
/**
|
||||
* Depend on all deps collected by this watcher.
|
||||
*/
|
||||
|
||||
Watcher.prototype.depend = function () {
|
||||
let i = this.deps.length
|
||||
while (i--) {
|
||||
this.deps[i].depend()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove self from all dependencies' subcriber list.
|
||||
*/
|
||||
|
||||
Watcher.prototype.teardown = function () {
|
||||
if (this.active) {
|
||||
// remove self from vm's watcher list
|
||||
// this is a somewhat expensive operation so we skip it
|
||||
// if the vm is being destroyed or is performing a v-for
|
||||
// re-render (the watcher list is then filtered by v-for).
|
||||
if (!this.vm._isBeingDestroyed && !this.vm._vForRemoving) {
|
||||
remove(this.vm._watchers, this)
|
||||
}
|
||||
/**
|
||||
* Clean up for dependency collection.
|
||||
*/
|
||||
afterGet () {
|
||||
Dep.target = prevTarget
|
||||
let i = this.deps.length
|
||||
while (i--) {
|
||||
this.deps[i].removeSub(this)
|
||||
const dep = this.deps[i]
|
||||
if (!this.newDepIds.has(dep.id)) {
|
||||
dep.removeSub(this)
|
||||
}
|
||||
}
|
||||
let tmp = this.depIds
|
||||
this.depIds = this.newDepIds
|
||||
this.newDepIds = tmp
|
||||
this.newDepIds.clear()
|
||||
tmp = this.deps
|
||||
this.deps = this.newDeps
|
||||
this.newDeps = tmp
|
||||
this.newDeps.length = 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscriber interface.
|
||||
* Will be called when a dependency changes.
|
||||
*/
|
||||
update () {
|
||||
if (this.lazy) {
|
||||
this.dirty = true
|
||||
} else if (this.sync) {
|
||||
this.run()
|
||||
} else {
|
||||
pushWatcher(this)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Batcher job interface.
|
||||
* Will be called by the batcher.
|
||||
*/
|
||||
run () {
|
||||
if (this.active) {
|
||||
const value = this.get()
|
||||
if (
|
||||
value !== this.value ||
|
||||
// Deep watchers and watchers on Object/Arrays should fire even
|
||||
// when the value is the same, because the value may
|
||||
// have mutated.
|
||||
isObject(value) ||
|
||||
this.deep
|
||||
) {
|
||||
// set new value
|
||||
const oldValue = this.value
|
||||
this.value = value
|
||||
this.cb.call(this.vm, value, oldValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluate the value of the watcher.
|
||||
* This only gets called for lazy watchers.
|
||||
*/
|
||||
evaluate () {
|
||||
// avoid overwriting another watcher that is being
|
||||
// collected.
|
||||
const current = Dep.target
|
||||
this.value = this.get()
|
||||
this.dirty = false
|
||||
Dep.target = current
|
||||
}
|
||||
|
||||
/**
|
||||
* Depend on all deps collected by this watcher.
|
||||
*/
|
||||
depend () {
|
||||
let i = this.deps.length
|
||||
while (i--) {
|
||||
this.deps[i].depend()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove self from all dependencies' subcriber list.
|
||||
*/
|
||||
teardown () {
|
||||
if (this.active) {
|
||||
// remove self from vm's watcher list
|
||||
// this is a somewhat expensive operation so we skip it
|
||||
// if the vm is being destroyed or is performing a v-for
|
||||
// re-render (the watcher list is then filtered by v-for).
|
||||
if (!this.vm._isBeingDestroyed && !this.vm._vForRemoving) {
|
||||
remove(this.vm._watchers, this)
|
||||
}
|
||||
let i = this.deps.length
|
||||
while (i--) {
|
||||
this.deps[i].removeSub(this)
|
||||
}
|
||||
this.active = false
|
||||
this.vm = this.cb = this.value = null
|
||||
}
|
||||
this.active = false
|
||||
this.vm = this.cb = this.value = null
|
||||
}
|
||||
}
|
||||
|
||||
@ -243,7 +221,6 @@ Watcher.prototype.teardown = function () {
|
||||
* @param {*} val
|
||||
* @param {Set} seen
|
||||
*/
|
||||
|
||||
const seenObjects = new Set()
|
||||
function traverse (val, seen) {
|
||||
let i, keys
|
||||
|
@ -1,5 +1,4 @@
|
||||
/* global MutationObserver */
|
||||
|
||||
// can we use __proto__?
|
||||
export const hasProto = '__proto__' in {}
|
||||
|
||||
@ -25,7 +24,6 @@ const isWechat = UA && UA.indexOf('micromessenger') > 0
|
||||
* @param {Function} cb
|
||||
* @param {Object} ctx
|
||||
*/
|
||||
|
||||
export const nextTick = (function () {
|
||||
let callbacks = []
|
||||
let pending = false
|
||||
@ -78,17 +76,19 @@ if (typeof Set !== 'undefined' && Set.toString().match(/native code/)) {
|
||||
_Set = Set
|
||||
} else {
|
||||
// a non-standard Set polyfill that only works with primitive keys.
|
||||
_Set = function () {
|
||||
this.set = Object.create(null)
|
||||
}
|
||||
_Set.prototype.has = function (key) {
|
||||
return this.set[key] !== undefined
|
||||
}
|
||||
_Set.prototype.add = function (key) {
|
||||
this.set[key] = 1
|
||||
}
|
||||
_Set.prototype.clear = function () {
|
||||
this.set = Object.create(null)
|
||||
_Set = class Set {
|
||||
constructor () {
|
||||
this.set = Object.create(null)
|
||||
}
|
||||
has (key) {
|
||||
return this.set[key] !== undefined
|
||||
}
|
||||
add (key) {
|
||||
this.set[key] = 1
|
||||
}
|
||||
clear () {
|
||||
this.set = Object.create(null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,6 @@
|
||||
* @param {String} str
|
||||
* @return {Boolean}
|
||||
*/
|
||||
|
||||
export function isReserved (str) {
|
||||
const c = (str + '').charCodeAt(0)
|
||||
return c === 0x24 || c === 0x5F
|
||||
@ -18,7 +17,6 @@ export function isReserved (str) {
|
||||
* @param {*} val
|
||||
* @param {Boolean} [enumerable]
|
||||
*/
|
||||
|
||||
export function def (obj, key, val, enumerable) {
|
||||
Object.defineProperty(obj, key, {
|
||||
value: val,
|
||||
@ -31,7 +29,6 @@ export function def (obj, key, val, enumerable) {
|
||||
/**
|
||||
* Parse simple path.
|
||||
*/
|
||||
|
||||
const bailRE = /[^\w\.]/
|
||||
export function parsePath (path) {
|
||||
if (bailRE.test(path)) {
|
||||
|
@ -23,13 +23,11 @@ import {
|
||||
* @param {*} childVal
|
||||
* @param {Vue} [vm]
|
||||
*/
|
||||
|
||||
const strats = config.optionMergeStrategies = Object.create(null)
|
||||
|
||||
/**
|
||||
* Options with restrictions
|
||||
*/
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
strats.el = strats.propsData = function (parent, child, vm, key) {
|
||||
if (!vm) {
|
||||
@ -55,7 +53,6 @@ if (process.env.NODE_ENV !== 'production') {
|
||||
/**
|
||||
* Helper that recursively merges two data objects together.
|
||||
*/
|
||||
|
||||
function mergeData (to, from) {
|
||||
let key, toVal, fromVal
|
||||
for (key in from) {
|
||||
@ -73,7 +70,6 @@ function mergeData (to, from) {
|
||||
/**
|
||||
* Data
|
||||
*/
|
||||
|
||||
strats.data = function (parentVal, childVal, vm) {
|
||||
if (!vm) {
|
||||
// in a Vue.extend merge, both should be functions
|
||||
@ -124,7 +120,6 @@ strats.data = function (parentVal, childVal, vm) {
|
||||
/**
|
||||
* Hooks and param attributes are merged as arrays.
|
||||
*/
|
||||
|
||||
function mergeHook (parentVal, childVal) {
|
||||
return childVal
|
||||
? parentVal
|
||||
@ -146,7 +141,6 @@ config._lifecycleHooks.forEach(hook => {
|
||||
* a three-way merge between constructor options, instance
|
||||
* options and parent options.
|
||||
*/
|
||||
|
||||
function mergeAssets (parentVal, childVal) {
|
||||
const res = Object.create(parentVal || null)
|
||||
return childVal
|
||||
@ -164,7 +158,6 @@ config._assetTypes.forEach(function (type) {
|
||||
* Watchers hashes should not overwrite one
|
||||
* another, so we merge them as arrays.
|
||||
*/
|
||||
|
||||
strats.watch = function (parentVal, childVal) {
|
||||
if (!childVal) return parentVal
|
||||
if (!parentVal) return childVal
|
||||
@ -186,7 +179,6 @@ strats.watch = function (parentVal, childVal) {
|
||||
/**
|
||||
* Other object hashes.
|
||||
*/
|
||||
|
||||
strats.props =
|
||||
strats.methods =
|
||||
strats.computed = function (parentVal, childVal) {
|
||||
@ -201,7 +193,6 @@ strats.computed = function (parentVal, childVal) {
|
||||
/**
|
||||
* Default strategy.
|
||||
*/
|
||||
|
||||
const defaultStrat = function (parentVal, childVal) {
|
||||
return childVal === undefined
|
||||
? parentVal
|
||||
@ -214,7 +205,6 @@ const defaultStrat = function (parentVal, childVal) {
|
||||
*
|
||||
* @param {Object} options
|
||||
*/
|
||||
|
||||
function guardComponents (options) {
|
||||
if (options.components) {
|
||||
const components = options.components
|
||||
@ -241,7 +231,6 @@ function guardComponents (options) {
|
||||
*
|
||||
* @param {Object} options
|
||||
*/
|
||||
|
||||
function guardProps (options) {
|
||||
const props = options.props
|
||||
if (!props) return
|
||||
@ -290,7 +279,6 @@ function guardDirectives (options) {
|
||||
* @param {Vue} [vm] - if vm is present, indicates this is
|
||||
* an instantiation merge.
|
||||
*/
|
||||
|
||||
export function mergeOptions (parent, child, vm) {
|
||||
guardComponents(child)
|
||||
guardProps(child)
|
||||
@ -339,7 +327,6 @@ export function mergeOptions (parent, child, vm) {
|
||||
* @param {Boolean} warnMissing
|
||||
* @return {Object|Function}
|
||||
*/
|
||||
|
||||
export function resolveAsset (options, type, id, warnMissing) {
|
||||
/* istanbul ignore if */
|
||||
if (typeof id !== 'string') {
|
||||
|
@ -29,7 +29,6 @@ export function validateProp (vm, key, propsData) {
|
||||
* @param {Object} prop
|
||||
* @return {*}
|
||||
*/
|
||||
|
||||
function getPropDefaultValue (vm, prop, name) {
|
||||
// no default, return undefined
|
||||
if (!hasOwn(prop, 'default')) {
|
||||
@ -63,7 +62,6 @@ function getPropDefaultValue (vm, prop, name) {
|
||||
* @param {Vue} vm
|
||||
* @param {Boolean} absent
|
||||
*/
|
||||
|
||||
function assertProp (prop, name, value, vm, absent) {
|
||||
if (prop.required && absent) {
|
||||
process.env.NODE_ENV !== 'production' && warn(
|
||||
@ -119,7 +117,6 @@ function assertProp (prop, name, value, vm, absent) {
|
||||
* @param {Function} type
|
||||
* @return {Object}
|
||||
*/
|
||||
|
||||
function assertType (value, type) {
|
||||
let valid
|
||||
let expectedType
|
||||
@ -156,7 +153,6 @@ function assertType (value, type) {
|
||||
* @param {String} type
|
||||
* @return {String}
|
||||
*/
|
||||
|
||||
function formatType (type) {
|
||||
return type
|
||||
? type.charAt(0).toUpperCase() + type.slice(1)
|
||||
@ -169,7 +165,6 @@ function formatType (type) {
|
||||
* @param {*} value
|
||||
* @return {String}
|
||||
*/
|
||||
|
||||
function formatValue (val) {
|
||||
return Object.prototype.toString.call(val).slice(8, -1)
|
||||
}
|
||||
|
@ -3,7 +3,6 @@
|
||||
* Simon Friis Vindum (@paldepind)
|
||||
* with custom modifications.
|
||||
*/
|
||||
|
||||
import VNode from './vnode'
|
||||
import { isPrimitive, renderString, warn } from '../util/index'
|
||||
|
||||
|
@ -45,7 +45,6 @@ Vue.prototype.$mount = function (el) {
|
||||
* @param {Element} el
|
||||
* @return {String}
|
||||
*/
|
||||
|
||||
function getOuterHTML (el) {
|
||||
if (el.outerHTML) {
|
||||
return el.outerHTML
|
||||
|
@ -11,7 +11,6 @@ const svgNS = namespaceMap.svg
|
||||
* @param {Element} el
|
||||
* @param {String} cls
|
||||
*/
|
||||
|
||||
export function setClass (el, cls) {
|
||||
/* istanbul ignore else */
|
||||
if (!isIE9 || el.namespaceURI === svgNS) {
|
||||
@ -27,7 +26,6 @@ export function setClass (el, cls) {
|
||||
* @param {Element} el
|
||||
* @param {String} cls
|
||||
*/
|
||||
|
||||
export function addClass (el, cls) {
|
||||
if (el.classList) {
|
||||
if (cls.indexOf(' ') > -1) {
|
||||
@ -49,7 +47,6 @@ export function addClass (el, cls) {
|
||||
* @param {Element} el
|
||||
* @param {String} cls
|
||||
*/
|
||||
|
||||
export function removeClass (el, cls) {
|
||||
if (el.classList) {
|
||||
if (cls.indexOf(' ') > -1) {
|
||||
@ -78,7 +75,6 @@ export function removeClass (el, cls) {
|
||||
* @param {Element} el
|
||||
* @return {String}
|
||||
*/
|
||||
|
||||
function getClass (el) {
|
||||
let classname = el.className
|
||||
if (typeof classname === 'object') {
|
||||
|
@ -14,7 +14,6 @@ export const isAndroid = UA && UA.indexOf('android') > 0
|
||||
* @param {String|Element} el
|
||||
* @return {Element}
|
||||
*/
|
||||
|
||||
export function query (el) {
|
||||
if (typeof el === 'string') {
|
||||
const selector = el
|
||||
|
@ -7,7 +7,6 @@ const MAX_STACK_DEPTH = 500
|
||||
* Licensed under the Apache License, Version 2.0
|
||||
* Modified by Evan You (@yyx990803)
|
||||
*/
|
||||
|
||||
export default class RenderStream extends stream.Readable {
|
||||
constructor (render) {
|
||||
super()
|
||||
|
@ -4,7 +4,6 @@
|
||||
* @param {*} val
|
||||
* @return {String}
|
||||
*/
|
||||
|
||||
export function renderString (val) {
|
||||
return val == null
|
||||
? ''
|
||||
@ -21,7 +20,6 @@ export function renderString (val) {
|
||||
* @param {Boolean} expectsLowerCase
|
||||
* @return {Function}
|
||||
*/
|
||||
|
||||
export function makeMap (str, expectsLowerCase) {
|
||||
const map = Object.create(null)
|
||||
const list = str.split(',')
|
||||
@ -36,7 +34,6 @@ export function makeMap (str, expectsLowerCase) {
|
||||
/**
|
||||
* Check if a tag is a built-in tag.
|
||||
*/
|
||||
|
||||
export const isBuiltInTag = makeMap('slot,component,render,transition', true)
|
||||
|
||||
/**
|
||||
@ -45,7 +42,6 @@ export const isBuiltInTag = makeMap('slot,component,render,transition', true)
|
||||
* @param {Array} arr
|
||||
* @param {*} item
|
||||
*/
|
||||
|
||||
export function remove (arr, item) {
|
||||
if (arr.length) {
|
||||
const index = arr.indexOf(item)
|
||||
@ -73,7 +69,6 @@ export function hasOwn (obj, key) {
|
||||
* @param {*} value
|
||||
* @return {Boolean}
|
||||
*/
|
||||
|
||||
export function isPrimitive (value) {
|
||||
return typeof value === 'string' || typeof value === 'number'
|
||||
}
|
||||
@ -84,7 +79,6 @@ export function isPrimitive (value) {
|
||||
* @param {Function} fn
|
||||
* @return {Function}
|
||||
*/
|
||||
|
||||
export function cached (fn) {
|
||||
const cache = Object.create(null)
|
||||
return function cachedFn (str) {
|
||||
@ -99,7 +93,6 @@ export function cached (fn) {
|
||||
* @param {String} str
|
||||
* @return {String}
|
||||
*/
|
||||
|
||||
const camelizeRE = /-(\w)/g
|
||||
export const camelize = cached(str => {
|
||||
return str.replace(camelizeRE, toUpper)
|
||||
@ -115,7 +108,6 @@ function toUpper (_, c) {
|
||||
* @param {String} str
|
||||
* @return {String}
|
||||
*/
|
||||
|
||||
const hyphenateRE = /([a-z\d])([A-Z])/g
|
||||
export const hyphenate = cached(str => {
|
||||
return str
|
||||
@ -130,7 +122,6 @@ export const hyphenate = cached(str => {
|
||||
* @param {Object} ctx
|
||||
* @return {Function}
|
||||
*/
|
||||
|
||||
export function bind (fn, ctx) {
|
||||
return function (a) {
|
||||
const l = arguments.length
|
||||
@ -149,7 +140,6 @@ export function bind (fn, ctx) {
|
||||
* @param {Number} [start] - start index
|
||||
* @return {Array}
|
||||
*/
|
||||
|
||||
export function toArray (list, start) {
|
||||
start = start || 0
|
||||
let i = list.length - start
|
||||
@ -166,7 +156,6 @@ export function toArray (list, start) {
|
||||
* @param {Object} to
|
||||
* @param {Object} from
|
||||
*/
|
||||
|
||||
export function extend (to, _from) {
|
||||
for (const key in _from) {
|
||||
to[key] = _from[key]
|
||||
@ -182,7 +171,6 @@ export function extend (to, _from) {
|
||||
* @param {*} obj
|
||||
* @return {Boolean}
|
||||
*/
|
||||
|
||||
export function isObject (obj) {
|
||||
return obj !== null && typeof obj === 'object'
|
||||
}
|
||||
@ -194,7 +182,6 @@ export function isObject (obj) {
|
||||
* @param {*} obj
|
||||
* @return {Boolean}
|
||||
*/
|
||||
|
||||
const toString = Object.prototype.toString
|
||||
const OBJECT_STRING = '[object Object]'
|
||||
export function isPlainObject (obj) {
|
||||
@ -207,5 +194,4 @@ export function isPlainObject (obj) {
|
||||
* @param {*} obj
|
||||
* @return {Boolean}
|
||||
*/
|
||||
|
||||
export const isArray = Array.isArray
|
||||
|
Loading…
Reference in New Issue
Block a user