} from './errorHandling'
import { queuePostRenderEffect } from './renderer'
import { warn } from './warning'
+import { DeprecationTypes, warnDeprecation } from './compat/deprecations'
+import { isCompatEnabled } from './compat/compatConfig'
export type WatchEffect = (onInvalidate: InvalidateCbRegistrator) => void
__DEV__ && warnInvalidSource(source)
}
+ // 2.x array mutation watch compat
+ if (__COMPAT__ && cb && !deep) {
+ const baseGetter = getter
+ getter = () => {
+ const val = baseGetter()
+ if (isArray(val)) {
+ __DEV__ && warnDeprecation(DeprecationTypes.WATCH_ARRAY)
+ if (isCompatEnabled(DeprecationTypes.WATCH_ARRAY)) {
+ traverse(val)
+ }
+ }
+ return val
+ }
+ }
+
if (cb && deep) {
const baseGetter = getter
getter = () => traverse(baseGetter())
if (cb) {
// watch(source, cb)
const newValue = runner()
- if (deep || forceTrigger || hasChanged(newValue, oldValue)) {
+ if (
+ deep ||
+ forceTrigger ||
+ hasChanged(newValue, oldValue) ||
+ (__COMPAT__ &&
+ isArray(newValue) &&
+ isCompatEnabled(DeprecationTypes.WATCH_ARRAY))
+ ) {
// cleanup before running cb again
if (cleanup) {
cleanup()
extend(globalCompatConfig, config)
}
-/**
- * @internal
- */
export function getCompatConfig(
key: DeprecationTypes
): DeprecationConfigItem | undefined {
return globalCompatConfig[key]
}
+
+/**
+ * @internal
+ */
+export function isCompatEnabled(key: DeprecationTypes): boolean {
+ const config = getCompatConfig(key)
+ return !config || config.mode !== 3
+}
OPTIONS_BEFORE_DESTROY = 'OPTIONS_BEFORE_DESTROY',
OPTIONS_DESTROYED = 'OPTIONS_DESTROYED',
+ V_ON_KEYCODE_MODIFIER = 'V_ON_KEYCODE_MODIFIER',
PROPS_DEFAULT_THIS = 'PROPS_DEFAULT_THIS',
-
CUSTOM_DIR = 'CUSTOM_DIR',
-
- V_ON_KEYCODE_MODIFIER = 'V_ON_KEYCODE_MODIFIER'
+ WATCH_ARRAY = 'WATCH_ARRAY'
}
type DeprecationData = {
message: `\`destroyed\` has been renamed to \`unmounted\`.`
},
+ [DeprecationTypes.V_ON_KEYCODE_MODIFIER]: {
+ message:
+ `Using keyCode as v-on modifier is no longer supported. ` +
+ `Use kebab-case key name modifiers instead.`,
+ link: `https://v3.vuejs.org/guide/migration/keycode-modifiers.html`
+ },
+
[DeprecationTypes.PROPS_DEFAULT_THIS]: {
message: (key: string) =>
`props default value function no longer has access to "this". ` +
link: `https://v3.vuejs.org/guide/migration/custom-directives.html`
},
- [DeprecationTypes.V_ON_KEYCODE_MODIFIER]: {
+ [DeprecationTypes.WATCH_ARRAY]: {
message:
- `Using keyCode as v-on modifier is no longer supported. ` +
- `Use kebab-case key name modifiers instead.`,
- link: `https://v3.vuejs.org/guide/migration/keycode-modifiers.html`
+ `"watch" option or vm.$watch on an array value will no longer ` +
+ `trigger on array mutation unless the "deep" option is specified. ` +
+ `If current usage is intended, you can suppress this warning with:` +
+ `\n\n configureCompat({ ${
+ DeprecationTypes.WATCH_ARRAY
+ }: { mode: 3 }})\n`,
+ link: `https://v3.vuejs.org/guide/migration/watch.html`
}
}
// check user config
const config = getCompatConfig(key)
- if (config && config.warning === false) {
+ if (
+ config &&
+ (config.warning === false || (config.mode === 3 && config.warning !== true))
+ ) {
return
}