feat: mixins/extends/assets options

This commit is contained in:
Evan You
2019-09-04 11:36:27 -04:00
parent 0bdf205a73
commit 02de984f1f
8 changed files with 124 additions and 76 deletions

View File

@@ -6,14 +6,15 @@ import {
ReactiveEffectOptions
} from '@vue/reactivity'
import { queueJob, queuePostFlushCb } from './scheduler'
import { EMPTY_OBJ, isObject, isArray, isFunction } from '@vue/shared'
import { EMPTY_OBJ, isObject, isArray, isFunction, isString } from '@vue/shared'
import { recordEffect } from './apiReactivity'
import { currentInstance } from './component'
import { currentInstance, ComponentInstance } from './component'
import {
ErrorTypes,
callWithErrorHandling,
callWithAsyncErrorHandling
} from './errorHandling'
import { onBeforeMount } from './apiLifecycle'
export interface WatchOptions {
lazy?: boolean
@@ -187,6 +188,20 @@ function doWatch(
}
}
// this.$watch
export function instanceWatch(
this: ComponentInstance,
source: string | Function,
cb: Function,
options?: WatchOptions
): () => void {
const ctx = this.renderProxy as any
const getter = isString(source) ? () => ctx[source] : source.bind(ctx)
const stop = watch(getter, cb.bind(ctx), options)
onBeforeMount(stop, this)
return stop
}
function traverse(value: any, seen: Set<any> = new Set()) {
if (!isObject(value) || seen.has(value)) {
return