vue 2.6.13 → 2.7.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -295
- package/compiler-sfc/index.d.ts +1 -0
- package/compiler-sfc/index.js +1 -0
- package/compiler-sfc/index.mjs +1 -0
- package/compiler-sfc/package.json +5 -0
- package/dist/vue.common.dev.js +11481 -11946
- package/dist/vue.common.prod.js +8 -3
- package/dist/vue.esm.browser.js +11321 -12011
- package/dist/vue.esm.browser.min.js +8 -3
- package/dist/vue.esm.js +11476 -11984
- package/dist/vue.js +11484 -11949
- package/dist/vue.min.js +8 -3
- package/dist/vue.runtime.common.dev.js +8427 -8421
- package/dist/vue.runtime.common.prod.js +8 -3
- package/dist/vue.runtime.esm.js +8436 -8454
- package/dist/vue.runtime.js +8430 -8424
- package/dist/vue.runtime.min.js +8 -3
- package/package.json +88 -111
- package/packages/compiler-sfc/dist/compiler-sfc.js +7 -0
- package/packages/compiler-sfc/node_modules/.bin/parser +17 -0
- package/packages/compiler-sfc/node_modules/.bin/sass +17 -0
- package/packages/compiler-sfc/package.json +30 -0
- package/src/compiler/{codeframe.js → codeframe.ts} +9 -7
- package/src/compiler/codegen/{events.js → events.ts} +21 -41
- package/src/compiler/codegen/{index.js → index.ts} +146 -136
- package/src/compiler/{create-compiler.js → create-compiler.ts} +26 -18
- package/src/compiler/directives/bind.ts +9 -0
- package/src/compiler/directives/{index.js → index.ts} +0 -2
- package/src/compiler/directives/{model.js → model.ts} +15 -18
- package/src/compiler/directives/{on.js → on.ts} +3 -4
- package/src/compiler/{error-detector.js → error-detector.ts} +61 -31
- package/src/compiler/{helpers.js → helpers.ts} +73 -61
- package/src/compiler/{index.js → index.ts} +2 -3
- package/src/compiler/{optimizer.js → optimizer.ts} +30 -23
- package/src/compiler/parser/{entity-decoder.js → entity-decoder.ts} +1 -3
- package/src/compiler/parser/{filter-parser.js → filter-parser.ts} +43 -24
- package/src/compiler/parser/{html-parser.js → html-parser.ts} +50 -29
- package/src/compiler/parser/{index.js → index.ts} +190 -172
- package/src/compiler/parser/{text-parser.js → text-parser.ts} +8 -9
- package/src/compiler/{to-function.js → to-function.ts} +27 -22
- package/src/core/components/{index.js → index.ts} +0 -0
- package/src/core/components/{keep-alive.js → keep-alive.ts} +42 -30
- package/src/core/{config.js → config.ts} +28 -30
- package/src/core/global-api/{assets.js → assets.ts} +8 -7
- package/src/core/global-api/{extend.js → extend.ts} +10 -13
- package/src/core/global-api/{index.js → index.ts} +4 -5
- package/src/core/global-api/{mixin.js → mixin.ts} +2 -3
- package/src/core/global-api/use.ts +23 -0
- package/src/core/{index.js → index.ts} +1 -1
- package/src/core/instance/{events.js → events.ts} +41 -24
- package/src/core/instance/{index.js → index.ts} +9 -5
- package/src/core/instance/{init.js → init.ts} +26 -15
- package/src/core/instance/inject.ts +72 -0
- package/src/core/instance/{lifecycle.js → lifecycle.ts} +86 -44
- package/src/core/instance/{proxy.js → proxy.ts} +29 -24
- package/src/core/instance/render-helpers/{bind-dynamic-keys.js → bind-dynamic-keys.ts} +6 -5
- package/src/core/instance/render-helpers/{bind-object-listeners.js → bind-object-listeners.ts} +4 -8
- package/src/core/instance/render-helpers/{bind-object-props.js → bind-object-props.ts} +12 -17
- package/src/core/instance/render-helpers/{check-keycodes.js → check-keycodes.ts} +5 -7
- package/src/core/instance/render-helpers/{index.js → index.ts} +1 -3
- package/src/core/instance/render-helpers/{render-list.js → render-list.ts} +12 -13
- package/src/core/instance/render-helpers/{render-slot.js → render-slot.ts} +10 -11
- package/src/core/instance/render-helpers/{render-static.js → render-static.ts} +7 -10
- package/src/core/instance/render-helpers/{resolve-filter.js → resolve-filter.ts} +1 -3
- package/src/core/instance/render-helpers/{resolve-scoped-slots.js → resolve-scoped-slots.ts} +11 -8
- package/src/core/instance/render-helpers/{resolve-slots.js → resolve-slots.ts} +12 -11
- package/src/core/instance/{render.js → render.ts} +66 -29
- package/src/core/instance/{state.js → state.ts} +100 -83
- package/src/core/observer/{array.js → array.ts} +11 -2
- package/src/core/observer/{dep.js → dep.ts} +37 -15
- package/src/core/observer/{index.js → index.ts} +137 -71
- package/src/core/observer/{scheduler.js → scheduler.ts} +42 -43
- package/src/core/observer/{traverse.js → traverse.ts} +10 -7
- package/src/core/observer/{watcher.js → watcher.ts} +88 -60
- package/src/core/util/{debug.js → debug.ts} +38 -34
- package/src/core/util/{env.js → env.ts} +27 -30
- package/src/core/util/{error.js → error.ts} +12 -14
- package/src/core/util/{index.js → index.ts} +0 -2
- package/src/core/util/{lang.js → lang.ts} +6 -7
- package/src/core/util/{next-tick.js → next-tick.ts} +16 -10
- package/src/core/util/{options.js → options.ts} +119 -114
- package/src/core/util/{perf.js → perf.ts} +5 -1
- package/src/core/util/{props.js → props.ts} +54 -50
- package/src/core/vdom/{create-component.js → create-component.ts} +51 -50
- package/src/core/vdom/{create-element.js → create-element.ts} +49 -43
- package/src/core/vdom/{create-functional-component.js → create-functional-component.ts} +52 -27
- package/src/core/vdom/helpers/{extract-props.js → extract-props.ts} +18 -18
- package/src/core/vdom/helpers/{get-first-component-child.js → get-first-component-child.ts} +6 -5
- package/src/core/vdom/helpers/{index.js → index.ts} +0 -2
- package/src/core/vdom/helpers/is-async-placeholder.ts +6 -0
- package/src/core/vdom/helpers/{merge-hook.js → merge-hook.ts} +7 -5
- package/src/core/vdom/helpers/{normalize-children.js → normalize-children.ts} +26 -16
- package/src/core/vdom/helpers/{normalize-scoped-slots.js → normalize-scoped-slots.ts} +23 -17
- package/src/core/vdom/helpers/{resolve-async-component.js → resolve-async-component.ts} +29 -37
- package/src/core/vdom/helpers/update-listeners.ts +101 -0
- package/src/core/vdom/modules/{directives.js → directives.ts} +20 -14
- package/src/core/vdom/modules/index.ts +4 -0
- package/src/core/vdom/modules/template-ref.ts +96 -0
- package/src/core/vdom/{patch.js → patch.ts} +239 -138
- package/src/core/vdom/{vnode.js → vnode.ts} +36 -31
- package/src/global.d.ts +15 -0
- package/src/platforms/web/compiler/directives/html.ts +8 -0
- package/src/platforms/web/compiler/directives/{index.js → index.ts} +0 -0
- package/src/platforms/web/compiler/directives/{model.js → model.ts} +47 -41
- package/src/platforms/web/compiler/directives/{text.js → text.ts} +2 -3
- package/src/platforms/web/compiler/{index.js → index.ts} +0 -2
- package/src/platforms/web/compiler/modules/{class.js → class.ts} +10 -15
- package/src/platforms/web/compiler/modules/{index.js → index.ts} +1 -5
- package/src/platforms/web/compiler/modules/{model.js → model.ts} +6 -11
- package/src/platforms/web/compiler/modules/{style.js → style.ts} +9 -14
- package/src/platforms/web/compiler/{options.js → options.ts} +1 -2
- package/src/platforms/web/compiler/{util.js → util.ts} +5 -7
- package/src/platforms/web/entry-compiler-sfc.ts +1 -0
- package/src/platforms/web/{entry-compiler.js → entry-compiler.ts} +1 -3
- package/src/platforms/web/{entry-runtime.js → entry-runtime-esm.ts} +2 -2
- package/src/platforms/web/entry-runtime-with-compiler-esm.ts +5 -0
- package/src/platforms/web/entry-runtime-with-compiler.ts +10 -0
- package/src/platforms/web/entry-runtime.ts +7 -0
- package/src/platforms/web/runtime/{class-util.js → class-util.ts} +2 -4
- package/src/platforms/web/runtime/components/{index.js → index.ts} +0 -0
- package/src/platforms/web/runtime/components/{transition-group.js → transition-group.ts} +59 -46
- package/src/platforms/web/runtime/components/{transition.js → transition.ts} +43 -36
- package/src/platforms/web/runtime/directives/{index.js → index.ts} +0 -0
- package/src/platforms/web/runtime/directives/{model.js → model.ts} +22 -21
- package/src/platforms/web/runtime/directives/{show.js → show.ts} +11 -10
- package/src/platforms/web/runtime/{index.js → index.ts} +9 -10
- package/src/platforms/web/runtime/modules/{attrs.js → attrs.ts} +12 -16
- package/src/platforms/web/runtime/modules/{class.js → class.ts} +7 -18
- package/src/platforms/web/runtime/modules/{dom-props.js → dom-props.ts} +24 -17
- package/src/platforms/web/runtime/modules/{events.js → events.ts} +22 -15
- package/src/platforms/web/runtime/modules/{index.js → index.ts} +1 -8
- package/src/platforms/web/runtime/modules/{style.js → style.ts} +24 -13
- package/src/platforms/web/runtime/modules/{transition.js → transition.ts} +61 -63
- package/src/platforms/web/runtime/node-ops.ts +66 -0
- package/src/platforms/web/runtime/{patch.js → patch.ts} +0 -2
- package/src/platforms/web/runtime/{transition-util.js → transition-util.ts} +63 -38
- package/src/platforms/web/{entry-runtime-with-compiler.js → runtime-with-compiler.ts} +28 -19
- package/src/platforms/web/util/{attrs.js → attrs.ts} +18 -14
- package/src/platforms/web/util/{class.js → class.ts} +23 -21
- package/src/platforms/web/util/{compat.js → compat.ts} +4 -4
- package/src/platforms/web/util/{element.js → element.ts} +21 -22
- package/src/platforms/web/util/{index.js → index.ts} +2 -6
- package/src/platforms/web/util/{style.js → style.ts} +12 -12
- package/src/sfc/{parser.js → parser.ts} +18 -15
- package/src/shared/{constants.js → constants.ts} +2 -6
- package/src/shared/{util.js → util.ts} +78 -55
- package/src/types/compiler.ts +224 -0
- package/src/types/component.ts +209 -0
- package/src/types/global-api.ts +37 -0
- package/src/types/modules.d.ts +15 -0
- package/src/types/options.ts +120 -0
- package/src/types/ssr.ts +27 -0
- package/src/types/utils.ts +3 -0
- package/src/types/vnode.ts +127 -0
- package/src/v3/apiInject.ts +66 -0
- package/src/v3/apiLifecycle.ts +53 -0
- package/src/v3/apiSetup.ts +161 -0
- package/src/v3/apiWatch.ts +355 -0
- package/src/v3/currentInstance.ts +23 -0
- package/src/v3/debug.ts +21 -0
- package/src/v3/h.ts +18 -0
- package/src/v3/index.ts +77 -0
- package/src/v3/reactivity/computed.ts +100 -0
- package/src/v3/reactivity/effect.ts +20 -0
- package/src/v3/reactivity/effectScope.ts +134 -0
- package/src/v3/reactivity/operations.ts +14 -0
- package/src/v3/reactivity/reactive.ts +123 -0
- package/src/v3/reactivity/readonly.ts +121 -0
- package/src/v3/reactivity/ref.ts +249 -0
- package/types/index.d.ts +10 -13
- package/types/options.d.ts +265 -132
- package/types/plugin.d.ts +4 -4
- package/types/umd.d.ts +47 -27
- package/types/v3-generated.d.ts +389 -0
- package/types/v3.d.ts +16 -0
- package/types/vnode.d.ts +70 -57
- package/types/vue.d.ts +292 -88
- package/dist/README.md +0 -122
- package/src/compiler/directives/bind.js +0 -11
- package/src/core/global-api/use.js +0 -23
- package/src/core/instance/inject.js +0 -73
- package/src/core/vdom/helpers/is-async-placeholder.js +0 -5
- package/src/core/vdom/helpers/update-listeners.js +0 -95
- package/src/core/vdom/modules/index.js +0 -7
- package/src/core/vdom/modules/ref.js +0 -45
- package/src/platforms/web/compiler/directives/html.js +0 -9
- package/src/platforms/web/entry-server-basic-renderer.js +0 -13
- package/src/platforms/web/entry-server-renderer.js +0 -27
- package/src/platforms/web/runtime/node-ops.js +0 -59
- package/src/platforms/web/server/compiler.js +0 -11
- package/src/platforms/web/server/directives/index.js +0 -7
- package/src/platforms/web/server/directives/model.js +0 -44
- package/src/platforms/web/server/directives/show.js +0 -12
- package/src/platforms/web/server/modules/attrs.js +0 -67
- package/src/platforms/web/server/modules/class.js +0 -11
- package/src/platforms/web/server/modules/dom-props.js +0 -50
- package/src/platforms/web/server/modules/index.js +0 -11
- package/src/platforms/web/server/modules/style.js +0 -41
- package/src/platforms/web/server/util.js +0 -101
- package/src/platforms/weex/compiler/directives/index.js +0 -5
- package/src/platforms/weex/compiler/directives/model.js +0 -33
- package/src/platforms/weex/compiler/index.js +0 -52
- package/src/platforms/weex/compiler/modules/append.js +0 -27
- package/src/platforms/weex/compiler/modules/class.js +0 -74
- package/src/platforms/weex/compiler/modules/index.js +0 -13
- package/src/platforms/weex/compiler/modules/props.js +0 -37
- package/src/platforms/weex/compiler/modules/recycle-list/component-root.js +0 -13
- package/src/platforms/weex/compiler/modules/recycle-list/component.js +0 -16
- package/src/platforms/weex/compiler/modules/recycle-list/index.js +0 -60
- package/src/platforms/weex/compiler/modules/recycle-list/recycle-list.js +0 -50
- package/src/platforms/weex/compiler/modules/recycle-list/text.js +0 -23
- package/src/platforms/weex/compiler/modules/recycle-list/v-bind.js +0 -21
- package/src/platforms/weex/compiler/modules/recycle-list/v-for.js +0 -33
- package/src/platforms/weex/compiler/modules/recycle-list/v-if.js +0 -63
- package/src/platforms/weex/compiler/modules/recycle-list/v-on.js +0 -25
- package/src/platforms/weex/compiler/modules/recycle-list/v-once.js +0 -19
- package/src/platforms/weex/compiler/modules/style.js +0 -87
- package/src/platforms/weex/entry-compiler.js +0 -2
- package/src/platforms/weex/entry-framework.js +0 -187
- package/src/platforms/weex/entry-runtime-factory.js +0 -6
- package/src/platforms/weex/runtime/components/index.js +0 -9
- package/src/platforms/weex/runtime/components/richtext.js +0 -82
- package/src/platforms/weex/runtime/components/transition-group.js +0 -148
- package/src/platforms/weex/runtime/components/transition.js +0 -9
- package/src/platforms/weex/runtime/directives/index.js +0 -2
- package/src/platforms/weex/runtime/index.js +0 -42
- package/src/platforms/weex/runtime/modules/attrs.js +0 -44
- package/src/platforms/weex/runtime/modules/class.js +0 -76
- package/src/platforms/weex/runtime/modules/events.js +0 -54
- package/src/platforms/weex/runtime/modules/index.js +0 -13
- package/src/platforms/weex/runtime/modules/style.js +0 -84
- package/src/platforms/weex/runtime/modules/transition.js +0 -270
- package/src/platforms/weex/runtime/node-ops.js +0 -91
- package/src/platforms/weex/runtime/patch.js +0 -16
- package/src/platforms/weex/runtime/recycle-list/render-component-template.js +0 -34
- package/src/platforms/weex/runtime/recycle-list/virtual-component.js +0 -136
- package/src/platforms/weex/runtime/text-node.js +0 -9
- package/src/platforms/weex/util/element.js +0 -52
- package/src/platforms/weex/util/index.js +0 -40
- package/src/platforms/weex/util/parser.js +0 -60
- package/src/server/bundle-renderer/create-bundle-renderer.js +0 -151
- package/src/server/bundle-renderer/create-bundle-runner.js +0 -150
- package/src/server/bundle-renderer/source-map-support.js +0 -45
- package/src/server/create-basic-renderer.js +0 -37
- package/src/server/create-renderer.js +0 -152
- package/src/server/optimizing-compiler/codegen.js +0 -264
- package/src/server/optimizing-compiler/index.js +0 -20
- package/src/server/optimizing-compiler/modules.js +0 -124
- package/src/server/optimizing-compiler/optimizer.js +0 -141
- package/src/server/optimizing-compiler/runtime-helpers.js +0 -150
- package/src/server/render-context.js +0 -130
- package/src/server/render-stream.js +0 -95
- package/src/server/render.js +0 -437
- package/src/server/template-renderer/create-async-file-mapper.js +0 -57
- package/src/server/template-renderer/index.js +0 -277
- package/src/server/template-renderer/parse-template.js +0 -42
- package/src/server/template-renderer/template-stream.js +0 -82
- package/src/server/util.js +0 -18
- package/src/server/webpack-plugin/client.js +0 -65
- package/src/server/webpack-plugin/server.js +0 -66
- package/src/server/webpack-plugin/util.js +0 -34
- package/src/server/write.js +0 -50
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import type { Component } from 'types/component'
|
|
3
2
|
import {
|
|
4
3
|
tip,
|
|
5
4
|
toArray,
|
|
5
|
+
isArray,
|
|
6
6
|
hyphenate,
|
|
7
7
|
formatComponentName,
|
|
8
8
|
invokeWithErrorHandling
|
|
9
9
|
} from '../util/index'
|
|
10
10
|
import { updateListeners } from '../vdom/helpers/index'
|
|
11
11
|
|
|
12
|
-
export function initEvents
|
|
12
|
+
export function initEvents(vm: Component) {
|
|
13
13
|
vm._events = Object.create(null)
|
|
14
14
|
vm._hasHookEvent = false
|
|
15
15
|
// init parent attached events
|
|
@@ -21,17 +21,17 @@ export function initEvents (vm: Component) {
|
|
|
21
21
|
|
|
22
22
|
let target: any
|
|
23
23
|
|
|
24
|
-
function add
|
|
24
|
+
function add(event, fn) {
|
|
25
25
|
target.$on(event, fn)
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
function remove
|
|
28
|
+
function remove(event, fn) {
|
|
29
29
|
target.$off(event, fn)
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
function createOnceHandler
|
|
32
|
+
function createOnceHandler(event, fn) {
|
|
33
33
|
const _target = target
|
|
34
|
-
return function onceHandler
|
|
34
|
+
return function onceHandler() {
|
|
35
35
|
const res = fn.apply(null, arguments)
|
|
36
36
|
if (res !== null) {
|
|
37
37
|
_target.$off(event, onceHandler)
|
|
@@ -39,26 +39,36 @@ function createOnceHandler (event, fn) {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
export function updateComponentListeners
|
|
42
|
+
export function updateComponentListeners(
|
|
43
43
|
vm: Component,
|
|
44
44
|
listeners: Object,
|
|
45
|
-
oldListeners
|
|
45
|
+
oldListeners?: Object | null
|
|
46
46
|
) {
|
|
47
47
|
target = vm
|
|
48
|
-
updateListeners(
|
|
48
|
+
updateListeners(
|
|
49
|
+
listeners,
|
|
50
|
+
oldListeners || {},
|
|
51
|
+
add,
|
|
52
|
+
remove,
|
|
53
|
+
createOnceHandler,
|
|
54
|
+
vm
|
|
55
|
+
)
|
|
49
56
|
target = undefined
|
|
50
57
|
}
|
|
51
58
|
|
|
52
|
-
export function eventsMixin
|
|
59
|
+
export function eventsMixin(Vue: typeof Component) {
|
|
53
60
|
const hookRE = /^hook:/
|
|
54
|
-
Vue.prototype.$on = function (
|
|
61
|
+
Vue.prototype.$on = function (
|
|
62
|
+
event: string | Array<string>,
|
|
63
|
+
fn: Function
|
|
64
|
+
): Component {
|
|
55
65
|
const vm: Component = this
|
|
56
|
-
if (
|
|
66
|
+
if (isArray(event)) {
|
|
57
67
|
for (let i = 0, l = event.length; i < l; i++) {
|
|
58
68
|
vm.$on(event[i], fn)
|
|
59
69
|
}
|
|
60
70
|
} else {
|
|
61
|
-
(vm._events[event] || (vm._events[event] = [])).push(fn)
|
|
71
|
+
;(vm._events[event] || (vm._events[event] = [])).push(fn)
|
|
62
72
|
// optimize hook:event cost by using a boolean flag marked at registration
|
|
63
73
|
// instead of a hash lookup
|
|
64
74
|
if (hookRE.test(event)) {
|
|
@@ -70,7 +80,7 @@ export function eventsMixin (Vue: Class<Component>) {
|
|
|
70
80
|
|
|
71
81
|
Vue.prototype.$once = function (event: string, fn: Function): Component {
|
|
72
82
|
const vm: Component = this
|
|
73
|
-
function on
|
|
83
|
+
function on() {
|
|
74
84
|
vm.$off(event, on)
|
|
75
85
|
fn.apply(vm, arguments)
|
|
76
86
|
}
|
|
@@ -79,7 +89,10 @@ export function eventsMixin (Vue: Class<Component>) {
|
|
|
79
89
|
return vm
|
|
80
90
|
}
|
|
81
91
|
|
|
82
|
-
Vue.prototype.$off = function (
|
|
92
|
+
Vue.prototype.$off = function (
|
|
93
|
+
event?: string | Array<string>,
|
|
94
|
+
fn?: Function
|
|
95
|
+
): Component {
|
|
83
96
|
const vm: Component = this
|
|
84
97
|
// all
|
|
85
98
|
if (!arguments.length) {
|
|
@@ -87,19 +100,19 @@ export function eventsMixin (Vue: Class<Component>) {
|
|
|
87
100
|
return vm
|
|
88
101
|
}
|
|
89
102
|
// array of events
|
|
90
|
-
if (
|
|
103
|
+
if (isArray(event)) {
|
|
91
104
|
for (let i = 0, l = event.length; i < l; i++) {
|
|
92
105
|
vm.$off(event[i], fn)
|
|
93
106
|
}
|
|
94
107
|
return vm
|
|
95
108
|
}
|
|
96
109
|
// specific event
|
|
97
|
-
const cbs = vm._events[event]
|
|
110
|
+
const cbs = vm._events[event!]
|
|
98
111
|
if (!cbs) {
|
|
99
112
|
return vm
|
|
100
113
|
}
|
|
101
114
|
if (!fn) {
|
|
102
|
-
vm._events[event] = null
|
|
115
|
+
vm._events[event!] = null
|
|
103
116
|
return vm
|
|
104
117
|
}
|
|
105
118
|
// specific handler
|
|
@@ -117,15 +130,19 @@ export function eventsMixin (Vue: Class<Component>) {
|
|
|
117
130
|
|
|
118
131
|
Vue.prototype.$emit = function (event: string): Component {
|
|
119
132
|
const vm: Component = this
|
|
120
|
-
if (
|
|
133
|
+
if (__DEV__) {
|
|
121
134
|
const lowerCaseEvent = event.toLowerCase()
|
|
122
135
|
if (lowerCaseEvent !== event && vm._events[lowerCaseEvent]) {
|
|
123
136
|
tip(
|
|
124
137
|
`Event "${lowerCaseEvent}" is emitted in component ` +
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
138
|
+
`${formatComponentName(
|
|
139
|
+
vm
|
|
140
|
+
)} but the handler is registered for "${event}". ` +
|
|
141
|
+
`Note that HTML attributes are case-insensitive and you cannot use ` +
|
|
142
|
+
`v-on to listen to camelCase events when using in-DOM templates. ` +
|
|
143
|
+
`You should probably use "${hyphenate(
|
|
144
|
+
event
|
|
145
|
+
)}" instead of "${event}".`
|
|
129
146
|
)
|
|
130
147
|
}
|
|
131
148
|
}
|
|
@@ -4,20 +4,24 @@ import { renderMixin } from './render'
|
|
|
4
4
|
import { eventsMixin } from './events'
|
|
5
5
|
import { lifecycleMixin } from './lifecycle'
|
|
6
6
|
import { warn } from '../util/index'
|
|
7
|
+
import type { GlobalAPI } from 'types/global-api'
|
|
7
8
|
|
|
8
|
-
function Vue
|
|
9
|
-
if (
|
|
10
|
-
!(this instanceof Vue)
|
|
11
|
-
) {
|
|
9
|
+
function Vue(options) {
|
|
10
|
+
if (__DEV__ && !(this instanceof Vue)) {
|
|
12
11
|
warn('Vue is a constructor and should be called with the `new` keyword')
|
|
13
12
|
}
|
|
14
13
|
this._init(options)
|
|
15
14
|
}
|
|
16
15
|
|
|
16
|
+
//@ts-expect-error Vue has function type
|
|
17
17
|
initMixin(Vue)
|
|
18
|
+
//@ts-expect-error Vue has function type
|
|
18
19
|
stateMixin(Vue)
|
|
20
|
+
//@ts-expect-error Vue has function type
|
|
19
21
|
eventsMixin(Vue)
|
|
22
|
+
//@ts-expect-error Vue has function type
|
|
20
23
|
lifecycleMixin(Vue)
|
|
24
|
+
//@ts-expect-error Vue has function type
|
|
21
25
|
renderMixin(Vue)
|
|
22
26
|
|
|
23
|
-
export default Vue
|
|
27
|
+
export default Vue as unknown as GlobalAPI
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
|
|
3
1
|
import config from '../config'
|
|
4
2
|
import { initProxy } from './proxy'
|
|
5
3
|
import { initState } from './state'
|
|
@@ -9,40 +7,48 @@ import { mark, measure } from '../util/perf'
|
|
|
9
7
|
import { initLifecycle, callHook } from './lifecycle'
|
|
10
8
|
import { initProvide, initInjections } from './inject'
|
|
11
9
|
import { extend, mergeOptions, formatComponentName } from '../util/index'
|
|
10
|
+
import type { Component } from 'types/component'
|
|
11
|
+
import type { InternalComponentOptions } from 'types/options'
|
|
12
|
+
import { EffectScope } from 'v3/reactivity/effectScope'
|
|
12
13
|
|
|
13
14
|
let uid = 0
|
|
14
15
|
|
|
15
|
-
export function initMixin
|
|
16
|
-
Vue.prototype._init = function (options?:
|
|
16
|
+
export function initMixin(Vue: typeof Component) {
|
|
17
|
+
Vue.prototype._init = function (options?: Record<string, any>) {
|
|
17
18
|
const vm: Component = this
|
|
18
19
|
// a uid
|
|
19
20
|
vm._uid = uid++
|
|
20
21
|
|
|
21
22
|
let startTag, endTag
|
|
22
23
|
/* istanbul ignore if */
|
|
23
|
-
if (
|
|
24
|
+
if (__DEV__ && config.performance && mark) {
|
|
24
25
|
startTag = `vue-perf-start:${vm._uid}`
|
|
25
26
|
endTag = `vue-perf-end:${vm._uid}`
|
|
26
27
|
mark(startTag)
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
// a flag to
|
|
30
|
+
// a flag to mark this as a Vue instance without having to do instanceof
|
|
31
|
+
// check
|
|
30
32
|
vm._isVue = true
|
|
33
|
+
// avoid instances from being observed
|
|
34
|
+
vm.__v_skip = true
|
|
35
|
+
// effect scope
|
|
36
|
+
vm._scope = new EffectScope(true /* detached */)
|
|
31
37
|
// merge options
|
|
32
38
|
if (options && options._isComponent) {
|
|
33
39
|
// optimize internal component instantiation
|
|
34
40
|
// since dynamic options merging is pretty slow, and none of the
|
|
35
41
|
// internal component options needs special treatment.
|
|
36
|
-
initInternalComponent(vm, options)
|
|
42
|
+
initInternalComponent(vm, options as any)
|
|
37
43
|
} else {
|
|
38
44
|
vm.$options = mergeOptions(
|
|
39
|
-
resolveConstructorOptions(vm.constructor),
|
|
45
|
+
resolveConstructorOptions(vm.constructor as any),
|
|
40
46
|
options || {},
|
|
41
47
|
vm
|
|
42
48
|
)
|
|
43
49
|
}
|
|
44
50
|
/* istanbul ignore else */
|
|
45
|
-
if (
|
|
51
|
+
if (__DEV__) {
|
|
46
52
|
initProxy(vm)
|
|
47
53
|
} else {
|
|
48
54
|
vm._renderProxy = vm
|
|
@@ -59,7 +65,7 @@ export function initMixin (Vue: Class<Component>) {
|
|
|
59
65
|
callHook(vm, 'created')
|
|
60
66
|
|
|
61
67
|
/* istanbul ignore if */
|
|
62
|
-
if (
|
|
68
|
+
if (__DEV__ && config.performance && mark) {
|
|
63
69
|
vm._name = formatComponentName(vm, false)
|
|
64
70
|
mark(endTag)
|
|
65
71
|
measure(`vue ${vm._name} init`, startTag, endTag)
|
|
@@ -71,14 +77,17 @@ export function initMixin (Vue: Class<Component>) {
|
|
|
71
77
|
}
|
|
72
78
|
}
|
|
73
79
|
|
|
74
|
-
export function initInternalComponent
|
|
75
|
-
|
|
80
|
+
export function initInternalComponent(
|
|
81
|
+
vm: Component,
|
|
82
|
+
options: InternalComponentOptions
|
|
83
|
+
) {
|
|
84
|
+
const opts = (vm.$options = Object.create((vm.constructor as any).options))
|
|
76
85
|
// doing this because it's faster than dynamic enumeration.
|
|
77
86
|
const parentVnode = options._parentVnode
|
|
78
87
|
opts.parent = options.parent
|
|
79
88
|
opts._parentVnode = parentVnode
|
|
80
89
|
|
|
81
|
-
const vnodeComponentOptions = parentVnode.componentOptions
|
|
90
|
+
const vnodeComponentOptions = parentVnode.componentOptions!
|
|
82
91
|
opts.propsData = vnodeComponentOptions.propsData
|
|
83
92
|
opts._parentListeners = vnodeComponentOptions.listeners
|
|
84
93
|
opts._renderChildren = vnodeComponentOptions.children
|
|
@@ -90,7 +99,7 @@ export function initInternalComponent (vm: Component, options: InternalComponent
|
|
|
90
99
|
}
|
|
91
100
|
}
|
|
92
101
|
|
|
93
|
-
export function resolveConstructorOptions
|
|
102
|
+
export function resolveConstructorOptions(Ctor: typeof Component) {
|
|
94
103
|
let options = Ctor.options
|
|
95
104
|
if (Ctor.super) {
|
|
96
105
|
const superOptions = resolveConstructorOptions(Ctor.super)
|
|
@@ -114,7 +123,9 @@ export function resolveConstructorOptions (Ctor: Class<Component>) {
|
|
|
114
123
|
return options
|
|
115
124
|
}
|
|
116
125
|
|
|
117
|
-
function resolveModifiedOptions
|
|
126
|
+
function resolveModifiedOptions(
|
|
127
|
+
Ctor: typeof Component
|
|
128
|
+
): Record<string, any> | null {
|
|
118
129
|
let modified
|
|
119
130
|
const latest = Ctor.options
|
|
120
131
|
const sealed = Ctor.sealedOptions
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { warn, hasSymbol, isFunction } from '../util/index'
|
|
2
|
+
import { defineReactive, toggleObserving } from '../observer/index'
|
|
3
|
+
import type { Component } from 'types/component'
|
|
4
|
+
import { provide } from 'v3/apiInject'
|
|
5
|
+
import { setCurrentInstance } from '../../v3/currentInstance'
|
|
6
|
+
|
|
7
|
+
export function initProvide(vm: Component) {
|
|
8
|
+
const provideOption = vm.$options.provide
|
|
9
|
+
if (provideOption) {
|
|
10
|
+
const provided = isFunction(provideOption)
|
|
11
|
+
? provideOption.call(vm)
|
|
12
|
+
: provideOption
|
|
13
|
+
const keys = hasSymbol ? Reflect.ownKeys(provided) : Object.keys(provided)
|
|
14
|
+
setCurrentInstance(vm)
|
|
15
|
+
for (let i = 0; i < keys.length; i++) {
|
|
16
|
+
provide(keys[i], provided[keys[i]])
|
|
17
|
+
}
|
|
18
|
+
setCurrentInstance()
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function initInjections(vm: Component) {
|
|
23
|
+
const result = resolveInject(vm.$options.inject, vm)
|
|
24
|
+
if (result) {
|
|
25
|
+
toggleObserving(false)
|
|
26
|
+
Object.keys(result).forEach(key => {
|
|
27
|
+
/* istanbul ignore else */
|
|
28
|
+
if (__DEV__) {
|
|
29
|
+
defineReactive(vm, key, result[key], () => {
|
|
30
|
+
warn(
|
|
31
|
+
`Avoid mutating an injected value directly since the changes will be ` +
|
|
32
|
+
`overwritten whenever the provided component re-renders. ` +
|
|
33
|
+
`injection being mutated: "${key}"`,
|
|
34
|
+
vm
|
|
35
|
+
)
|
|
36
|
+
})
|
|
37
|
+
} else {
|
|
38
|
+
defineReactive(vm, key, result[key])
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
toggleObserving(true)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function resolveInject(
|
|
46
|
+
inject: any,
|
|
47
|
+
vm: Component
|
|
48
|
+
): Record<string, any> | undefined | null {
|
|
49
|
+
if (inject) {
|
|
50
|
+
// inject is :any because flow is not smart enough to figure out cached
|
|
51
|
+
const result = Object.create(null)
|
|
52
|
+
const keys = hasSymbol ? Reflect.ownKeys(inject) : Object.keys(inject)
|
|
53
|
+
|
|
54
|
+
for (let i = 0; i < keys.length; i++) {
|
|
55
|
+
const key = keys[i]
|
|
56
|
+
// #6574 in case the inject object is observed...
|
|
57
|
+
if (key === '__ob__') continue
|
|
58
|
+
const provideKey = inject[key].from
|
|
59
|
+
if (provideKey in vm._provided) {
|
|
60
|
+
result[key] = vm._provided[provideKey]
|
|
61
|
+
} else if ('default' in inject[key]) {
|
|
62
|
+
const provideDefault = inject[key].default
|
|
63
|
+
result[key] = isFunction(provideDefault)
|
|
64
|
+
? provideDefault.call(vm)
|
|
65
|
+
: provideDefault
|
|
66
|
+
} else if (__DEV__) {
|
|
67
|
+
warn(`Injection "${key as string}" not found`, vm)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return result
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
|
|
3
1
|
import config from '../config'
|
|
4
|
-
import Watcher from '../observer/watcher'
|
|
2
|
+
import Watcher, { WatcherOptions } from '../observer/watcher'
|
|
5
3
|
import { mark, measure } from '../util/perf'
|
|
6
|
-
import { createEmptyVNode } from '../vdom/vnode'
|
|
4
|
+
import VNode, { createEmptyVNode } from '../vdom/vnode'
|
|
7
5
|
import { updateComponentListeners } from './events'
|
|
8
6
|
import { resolveSlots } from './render-helpers/resolve-slots'
|
|
9
7
|
import { toggleObserving } from '../observer/index'
|
|
10
8
|
import { pushTarget, popTarget } from '../observer/dep'
|
|
9
|
+
import type { Component } from 'types/component'
|
|
10
|
+
import type { MountedComponentVNode } from 'types/vnode'
|
|
11
11
|
|
|
12
12
|
import {
|
|
13
13
|
warn,
|
|
@@ -17,6 +17,8 @@ import {
|
|
|
17
17
|
validateProp,
|
|
18
18
|
invokeWithErrorHandling
|
|
19
19
|
} from '../util/index'
|
|
20
|
+
import { currentInstance, setCurrentInstance } from 'v3/currentInstance'
|
|
21
|
+
import { syncSetupAttrs } from 'v3/apiSetup'
|
|
20
22
|
|
|
21
23
|
export let activeInstance: any = null
|
|
22
24
|
export let isUpdatingChildComponent: boolean = false
|
|
@@ -29,7 +31,7 @@ export function setActiveInstance(vm: Component) {
|
|
|
29
31
|
}
|
|
30
32
|
}
|
|
31
33
|
|
|
32
|
-
export function initLifecycle
|
|
34
|
+
export function initLifecycle(vm: Component) {
|
|
33
35
|
const options = vm.$options
|
|
34
36
|
|
|
35
37
|
// locate first non-abstract parent
|
|
@@ -47,6 +49,7 @@ export function initLifecycle (vm: Component) {
|
|
|
47
49
|
vm.$children = []
|
|
48
50
|
vm.$refs = {}
|
|
49
51
|
|
|
52
|
+
vm._provided = parent ? parent._provided : Object.create(null)
|
|
50
53
|
vm._watcher = null
|
|
51
54
|
vm._inactive = null
|
|
52
55
|
vm._directInactive = false
|
|
@@ -55,7 +58,7 @@ export function initLifecycle (vm: Component) {
|
|
|
55
58
|
vm._isBeingDestroyed = false
|
|
56
59
|
}
|
|
57
60
|
|
|
58
|
-
export function lifecycleMixin
|
|
61
|
+
export function lifecycleMixin(Vue: typeof Component) {
|
|
59
62
|
Vue.prototype._update = function (vnode: VNode, hydrating?: boolean) {
|
|
60
63
|
const vm: Component = this
|
|
61
64
|
const prevEl = vm.$el
|
|
@@ -106,14 +109,9 @@ export function lifecycleMixin (Vue: Class<Component>) {
|
|
|
106
109
|
if (parent && !parent._isBeingDestroyed && !vm.$options.abstract) {
|
|
107
110
|
remove(parent.$children, vm)
|
|
108
111
|
}
|
|
109
|
-
// teardown
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
let i = vm._watchers.length
|
|
114
|
-
while (i--) {
|
|
115
|
-
vm._watchers[i].teardown()
|
|
116
|
-
}
|
|
112
|
+
// teardown scope. this includes both the render watcher and other
|
|
113
|
+
// watchers created
|
|
114
|
+
vm._scope.stop()
|
|
117
115
|
// remove reference from data ob
|
|
118
116
|
// frozen object may not have observer.
|
|
119
117
|
if (vm._data.__ob__) {
|
|
@@ -138,22 +136,26 @@ export function lifecycleMixin (Vue: Class<Component>) {
|
|
|
138
136
|
}
|
|
139
137
|
}
|
|
140
138
|
|
|
141
|
-
export function mountComponent
|
|
139
|
+
export function mountComponent(
|
|
142
140
|
vm: Component,
|
|
143
|
-
el:
|
|
141
|
+
el: Element | null | undefined,
|
|
144
142
|
hydrating?: boolean
|
|
145
143
|
): Component {
|
|
146
144
|
vm.$el = el
|
|
147
145
|
if (!vm.$options.render) {
|
|
146
|
+
// @ts-expect-error invalid type
|
|
148
147
|
vm.$options.render = createEmptyVNode
|
|
149
|
-
if (
|
|
148
|
+
if (__DEV__) {
|
|
150
149
|
/* istanbul ignore if */
|
|
151
|
-
if (
|
|
152
|
-
vm.$options.
|
|
150
|
+
if (
|
|
151
|
+
(vm.$options.template && vm.$options.template.charAt(0) !== '#') ||
|
|
152
|
+
vm.$options.el ||
|
|
153
|
+
el
|
|
154
|
+
) {
|
|
153
155
|
warn(
|
|
154
156
|
'You are using the runtime-only build of Vue where the template ' +
|
|
155
|
-
|
|
156
|
-
|
|
157
|
+
'compiler is not available. Either pre-compile the templates into ' +
|
|
158
|
+
'render functions, or use the compiler-included build.',
|
|
157
159
|
vm
|
|
158
160
|
)
|
|
159
161
|
} else {
|
|
@@ -168,7 +170,7 @@ export function mountComponent (
|
|
|
168
170
|
|
|
169
171
|
let updateComponent
|
|
170
172
|
/* istanbul ignore if */
|
|
171
|
-
if (
|
|
173
|
+
if (__DEV__ && config.performance && mark) {
|
|
172
174
|
updateComponent = () => {
|
|
173
175
|
const name = vm._name
|
|
174
176
|
const id = vm._uid
|
|
@@ -191,35 +193,54 @@ export function mountComponent (
|
|
|
191
193
|
}
|
|
192
194
|
}
|
|
193
195
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
// component's mounted hook), which relies on vm._watcher being already defined
|
|
197
|
-
new Watcher(vm, updateComponent, noop, {
|
|
198
|
-
before () {
|
|
196
|
+
const watcherOptions: WatcherOptions = {
|
|
197
|
+
before() {
|
|
199
198
|
if (vm._isMounted && !vm._isDestroyed) {
|
|
200
199
|
callHook(vm, 'beforeUpdate')
|
|
201
200
|
}
|
|
202
201
|
}
|
|
203
|
-
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (__DEV__) {
|
|
205
|
+
watcherOptions.onTrack = e => callHook(vm, 'renderTracked', [e])
|
|
206
|
+
watcherOptions.onTrigger = e => callHook(vm, 'renderTriggered', [e])
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// we set this to vm._watcher inside the watcher's constructor
|
|
210
|
+
// since the watcher's initial patch may call $forceUpdate (e.g. inside child
|
|
211
|
+
// component's mounted hook), which relies on vm._watcher being already defined
|
|
212
|
+
new Watcher(
|
|
213
|
+
vm,
|
|
214
|
+
updateComponent,
|
|
215
|
+
noop,
|
|
216
|
+
watcherOptions,
|
|
217
|
+
true /* isRenderWatcher */
|
|
218
|
+
)
|
|
204
219
|
hydrating = false
|
|
205
220
|
|
|
206
221
|
// manually mounted instance, call mounted on self
|
|
207
222
|
// mounted is called for render-created child components in its inserted hook
|
|
208
223
|
if (vm.$vnode == null) {
|
|
224
|
+
const preWatchers = vm._preWatchers
|
|
225
|
+
if (preWatchers) {
|
|
226
|
+
for (let i = 0; i < preWatchers.length; i++) {
|
|
227
|
+
preWatchers[i].run()
|
|
228
|
+
}
|
|
229
|
+
}
|
|
209
230
|
vm._isMounted = true
|
|
210
231
|
callHook(vm, 'mounted')
|
|
211
232
|
}
|
|
212
233
|
return vm
|
|
213
234
|
}
|
|
214
235
|
|
|
215
|
-
export function updateChildComponent
|
|
236
|
+
export function updateChildComponent(
|
|
216
237
|
vm: Component,
|
|
217
|
-
propsData:
|
|
218
|
-
listeners:
|
|
238
|
+
propsData: Record<string, any> | null | undefined,
|
|
239
|
+
listeners: Record<string, Function | Array<Function>> | undefined,
|
|
219
240
|
parentVnode: MountedComponentVNode,
|
|
220
|
-
renderChildren
|
|
241
|
+
renderChildren?: Array<VNode> | null
|
|
221
242
|
) {
|
|
222
|
-
if (
|
|
243
|
+
if (__DEV__) {
|
|
223
244
|
isUpdatingChildComponent = true
|
|
224
245
|
}
|
|
225
246
|
|
|
@@ -241,16 +262,18 @@ export function updateChildComponent (
|
|
|
241
262
|
// Any static slot children from the parent may have changed during parent's
|
|
242
263
|
// update. Dynamic scoped slots may also have changed. In such cases, a forced
|
|
243
264
|
// update is necessary to ensure correctness.
|
|
244
|
-
|
|
245
|
-
renderChildren ||
|
|
246
|
-
vm.$options._renderChildren ||
|
|
265
|
+
let needsForceUpdate = !!(
|
|
266
|
+
renderChildren || // has new static slots
|
|
267
|
+
vm.$options._renderChildren || // has old static slots
|
|
247
268
|
hasDynamicScopedSlot
|
|
248
269
|
)
|
|
249
270
|
|
|
271
|
+
const prevVNode = vm.$vnode
|
|
250
272
|
vm.$options._parentVnode = parentVnode
|
|
251
273
|
vm.$vnode = parentVnode // update vm's placeholder node without re-render
|
|
252
274
|
|
|
253
|
-
if (vm._vnode) {
|
|
275
|
+
if (vm._vnode) {
|
|
276
|
+
// update child tree's parent
|
|
254
277
|
vm._vnode.parent = parentVnode
|
|
255
278
|
}
|
|
256
279
|
vm.$options._renderChildren = renderChildren
|
|
@@ -258,7 +281,23 @@ export function updateChildComponent (
|
|
|
258
281
|
// update $attrs and $listeners hash
|
|
259
282
|
// these are also reactive so they may trigger child update if the child
|
|
260
283
|
// used them during render
|
|
261
|
-
|
|
284
|
+
const attrs = parentVnode.data.attrs || emptyObject
|
|
285
|
+
if (vm._attrsProxy) {
|
|
286
|
+
// force update if attrs are accessed and has changed since it may be
|
|
287
|
+
// passed to a child component.
|
|
288
|
+
if (
|
|
289
|
+
syncSetupAttrs(
|
|
290
|
+
vm._attrsProxy,
|
|
291
|
+
attrs,
|
|
292
|
+
(prevVNode.data && prevVNode.data.attrs) || emptyObject,
|
|
293
|
+
vm
|
|
294
|
+
)
|
|
295
|
+
) {
|
|
296
|
+
needsForceUpdate = true
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
vm.$attrs = attrs
|
|
300
|
+
|
|
262
301
|
vm.$listeners = listeners || emptyObject
|
|
263
302
|
|
|
264
303
|
// update props
|
|
@@ -288,19 +327,19 @@ export function updateChildComponent (
|
|
|
288
327
|
vm.$forceUpdate()
|
|
289
328
|
}
|
|
290
329
|
|
|
291
|
-
if (
|
|
330
|
+
if (__DEV__) {
|
|
292
331
|
isUpdatingChildComponent = false
|
|
293
332
|
}
|
|
294
333
|
}
|
|
295
334
|
|
|
296
|
-
function isInInactiveTree
|
|
335
|
+
function isInInactiveTree(vm) {
|
|
297
336
|
while (vm && (vm = vm.$parent)) {
|
|
298
337
|
if (vm._inactive) return true
|
|
299
338
|
}
|
|
300
339
|
return false
|
|
301
340
|
}
|
|
302
341
|
|
|
303
|
-
export function activateChildComponent
|
|
342
|
+
export function activateChildComponent(vm: Component, direct?: boolean) {
|
|
304
343
|
if (direct) {
|
|
305
344
|
vm._directInactive = false
|
|
306
345
|
if (isInInactiveTree(vm)) {
|
|
@@ -318,7 +357,7 @@ export function activateChildComponent (vm: Component, direct?: boolean) {
|
|
|
318
357
|
}
|
|
319
358
|
}
|
|
320
359
|
|
|
321
|
-
export function deactivateChildComponent
|
|
360
|
+
export function deactivateChildComponent(vm: Component, direct?: boolean) {
|
|
322
361
|
if (direct) {
|
|
323
362
|
vm._directInactive = true
|
|
324
363
|
if (isInInactiveTree(vm)) {
|
|
@@ -334,18 +373,21 @@ export function deactivateChildComponent (vm: Component, direct?: boolean) {
|
|
|
334
373
|
}
|
|
335
374
|
}
|
|
336
375
|
|
|
337
|
-
export function callHook
|
|
376
|
+
export function callHook(vm: Component, hook: string, args?: any[]) {
|
|
338
377
|
// #7573 disable dep collection when invoking lifecycle hooks
|
|
339
378
|
pushTarget()
|
|
379
|
+
const prev = currentInstance
|
|
380
|
+
setCurrentInstance(vm)
|
|
340
381
|
const handlers = vm.$options[hook]
|
|
341
382
|
const info = `${hook} hook`
|
|
342
383
|
if (handlers) {
|
|
343
384
|
for (let i = 0, j = handlers.length; i < j; i++) {
|
|
344
|
-
invokeWithErrorHandling(handlers[i], vm, null, vm, info)
|
|
385
|
+
invokeWithErrorHandling(handlers[i], vm, args || null, vm, info)
|
|
345
386
|
}
|
|
346
387
|
}
|
|
347
388
|
if (vm._hasHookEvent) {
|
|
348
389
|
vm.$emit('hook:' + hook)
|
|
349
390
|
}
|
|
391
|
+
setCurrentInstance(prev)
|
|
350
392
|
popTarget()
|
|
351
393
|
}
|