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
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { isServerRendering, noop, warn, def, isFunction } from 'core/util'
|
|
2
|
+
import { Ref, RefFlag } from './ref'
|
|
3
|
+
import Watcher from 'core/observer/watcher'
|
|
4
|
+
import Dep from 'core/observer/dep'
|
|
5
|
+
import { currentInstance } from '../currentInstance'
|
|
6
|
+
import { ReactiveFlags } from './reactive'
|
|
7
|
+
import { TrackOpTypes } from './operations'
|
|
8
|
+
import { DebuggerOptions } from '../debug'
|
|
9
|
+
|
|
10
|
+
declare const ComputedRefSymbol: unique symbol
|
|
11
|
+
|
|
12
|
+
export interface ComputedRef<T = any> extends WritableComputedRef<T> {
|
|
13
|
+
readonly value: T
|
|
14
|
+
[ComputedRefSymbol]: true
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface WritableComputedRef<T> extends Ref<T> {
|
|
18
|
+
readonly effect: any /* Watcher */
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type ComputedGetter<T> = (...args: any[]) => T
|
|
22
|
+
export type ComputedSetter<T> = (v: T) => void
|
|
23
|
+
|
|
24
|
+
export interface WritableComputedOptions<T> {
|
|
25
|
+
get: ComputedGetter<T>
|
|
26
|
+
set: ComputedSetter<T>
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function computed<T>(
|
|
30
|
+
getter: ComputedGetter<T>,
|
|
31
|
+
debugOptions?: DebuggerOptions
|
|
32
|
+
): ComputedRef<T>
|
|
33
|
+
export function computed<T>(
|
|
34
|
+
options: WritableComputedOptions<T>,
|
|
35
|
+
debugOptions?: DebuggerOptions
|
|
36
|
+
): WritableComputedRef<T>
|
|
37
|
+
export function computed<T>(
|
|
38
|
+
getterOrOptions: ComputedGetter<T> | WritableComputedOptions<T>,
|
|
39
|
+
debugOptions?: DebuggerOptions
|
|
40
|
+
) {
|
|
41
|
+
let getter: ComputedGetter<T>
|
|
42
|
+
let setter: ComputedSetter<T>
|
|
43
|
+
|
|
44
|
+
const onlyGetter = isFunction(getterOrOptions)
|
|
45
|
+
if (onlyGetter) {
|
|
46
|
+
getter = getterOrOptions
|
|
47
|
+
setter = __DEV__
|
|
48
|
+
? () => {
|
|
49
|
+
warn('Write operation failed: computed value is readonly')
|
|
50
|
+
}
|
|
51
|
+
: noop
|
|
52
|
+
} else {
|
|
53
|
+
getter = getterOrOptions.get
|
|
54
|
+
setter = getterOrOptions.set
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const watcher = isServerRendering()
|
|
58
|
+
? null
|
|
59
|
+
: new Watcher(currentInstance, getter, noop, { lazy: true })
|
|
60
|
+
|
|
61
|
+
if (__DEV__ && watcher && debugOptions) {
|
|
62
|
+
watcher.onTrack = debugOptions.onTrack
|
|
63
|
+
watcher.onTrigger = debugOptions.onTrigger
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const ref = {
|
|
67
|
+
// some libs rely on the presence effect for checking computed refs
|
|
68
|
+
// from normal refs, but the implementation doesn't matter
|
|
69
|
+
effect: watcher,
|
|
70
|
+
get value() {
|
|
71
|
+
if (watcher) {
|
|
72
|
+
if (watcher.dirty) {
|
|
73
|
+
watcher.evaluate()
|
|
74
|
+
}
|
|
75
|
+
if (Dep.target) {
|
|
76
|
+
if (__DEV__ && Dep.target.onTrack) {
|
|
77
|
+
Dep.target.onTrack({
|
|
78
|
+
effect: Dep.target,
|
|
79
|
+
target: ref,
|
|
80
|
+
type: TrackOpTypes.GET,
|
|
81
|
+
key: 'value'
|
|
82
|
+
})
|
|
83
|
+
}
|
|
84
|
+
watcher.depend()
|
|
85
|
+
}
|
|
86
|
+
return watcher.value
|
|
87
|
+
} else {
|
|
88
|
+
return getter()
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
set value(newVal) {
|
|
92
|
+
setter(newVal)
|
|
93
|
+
}
|
|
94
|
+
} as any
|
|
95
|
+
|
|
96
|
+
def(ref, RefFlag, true)
|
|
97
|
+
def(ref, ReactiveFlags.IS_READONLY, onlyGetter)
|
|
98
|
+
|
|
99
|
+
return ref
|
|
100
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import Watcher from 'core/observer/watcher'
|
|
2
|
+
import { noop } from 'shared/util'
|
|
3
|
+
import { currentInstance } from '../currentInstance'
|
|
4
|
+
|
|
5
|
+
// export type EffectScheduler = (...args: any[]) => any
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @internal since we are not exposing this in Vue 2, it's used only for
|
|
9
|
+
* internal testing.
|
|
10
|
+
*/
|
|
11
|
+
export function effect(fn: () => any, scheduler?: (cb: any) => void) {
|
|
12
|
+
const watcher = new Watcher(currentInstance, fn, noop, {
|
|
13
|
+
sync: true
|
|
14
|
+
})
|
|
15
|
+
if (scheduler) {
|
|
16
|
+
watcher.update = () => {
|
|
17
|
+
scheduler(() => watcher.run())
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import Watcher from 'core/observer/watcher'
|
|
2
|
+
import { warn } from 'core/util'
|
|
3
|
+
|
|
4
|
+
export let activeEffectScope: EffectScope | undefined
|
|
5
|
+
|
|
6
|
+
export class EffectScope {
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
active = true
|
|
11
|
+
/**
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
effects: Watcher[] = []
|
|
15
|
+
/**
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
cleanups: (() => void)[] = []
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* only assigned by undetached scope
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
parent: EffectScope | undefined
|
|
25
|
+
/**
|
|
26
|
+
* record undetached scopes
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
scopes: EffectScope[] | undefined
|
|
30
|
+
/**
|
|
31
|
+
* track a child scope's index in its parent's scopes array for optimized
|
|
32
|
+
* removal
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
private index: number | undefined
|
|
36
|
+
|
|
37
|
+
constructor(detached = false) {
|
|
38
|
+
if (!detached && activeEffectScope) {
|
|
39
|
+
this.parent = activeEffectScope
|
|
40
|
+
this.index =
|
|
41
|
+
(activeEffectScope.scopes || (activeEffectScope.scopes = [])).push(
|
|
42
|
+
this
|
|
43
|
+
) - 1
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
run<T>(fn: () => T): T | undefined {
|
|
48
|
+
if (this.active) {
|
|
49
|
+
const currentEffectScope = activeEffectScope
|
|
50
|
+
try {
|
|
51
|
+
activeEffectScope = this
|
|
52
|
+
return fn()
|
|
53
|
+
} finally {
|
|
54
|
+
activeEffectScope = currentEffectScope
|
|
55
|
+
}
|
|
56
|
+
} else if (__DEV__) {
|
|
57
|
+
warn(`cannot run an inactive effect scope.`)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* This should only be called on non-detached scopes
|
|
63
|
+
* @internal
|
|
64
|
+
*/
|
|
65
|
+
on() {
|
|
66
|
+
activeEffectScope = this
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* This should only be called on non-detached scopes
|
|
71
|
+
* @internal
|
|
72
|
+
*/
|
|
73
|
+
off() {
|
|
74
|
+
activeEffectScope = this.parent
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
stop(fromParent?: boolean) {
|
|
78
|
+
if (this.active) {
|
|
79
|
+
let i, l
|
|
80
|
+
for (i = 0, l = this.effects.length; i < l; i++) {
|
|
81
|
+
this.effects[i].teardown()
|
|
82
|
+
}
|
|
83
|
+
for (i = 0, l = this.cleanups.length; i < l; i++) {
|
|
84
|
+
this.cleanups[i]()
|
|
85
|
+
}
|
|
86
|
+
if (this.scopes) {
|
|
87
|
+
for (i = 0, l = this.scopes.length; i < l; i++) {
|
|
88
|
+
this.scopes[i].stop(true)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// nested scope, dereference from parent to avoid memory leaks
|
|
92
|
+
if (this.parent && !fromParent) {
|
|
93
|
+
// optimized O(1) removal
|
|
94
|
+
const last = this.parent.scopes!.pop()
|
|
95
|
+
if (last && last !== this) {
|
|
96
|
+
this.parent.scopes![this.index!] = last
|
|
97
|
+
last.index = this.index!
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
this.active = false
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function effectScope(detached?: boolean) {
|
|
106
|
+
return new EffectScope(detached)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @internal
|
|
111
|
+
*/
|
|
112
|
+
export function recordEffectScope(
|
|
113
|
+
effect: Watcher,
|
|
114
|
+
scope: EffectScope | undefined = activeEffectScope
|
|
115
|
+
) {
|
|
116
|
+
if (scope && scope.active) {
|
|
117
|
+
scope.effects.push(effect)
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function getCurrentScope() {
|
|
122
|
+
return activeEffectScope
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function onScopeDispose(fn: () => void) {
|
|
126
|
+
if (activeEffectScope) {
|
|
127
|
+
activeEffectScope.cleanups.push(fn)
|
|
128
|
+
} else if (__DEV__) {
|
|
129
|
+
warn(
|
|
130
|
+
`onScopeDispose() is called when there is no active effect scope` +
|
|
131
|
+
` to be associated with.`
|
|
132
|
+
)
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// using literal strings instead of numbers so that it's easier to inspect
|
|
2
|
+
// debugger events
|
|
3
|
+
|
|
4
|
+
export const enum TrackOpTypes {
|
|
5
|
+
GET = 'get',
|
|
6
|
+
TOUCH = 'touch'
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const enum TriggerOpTypes {
|
|
10
|
+
SET = 'set',
|
|
11
|
+
ADD = 'add',
|
|
12
|
+
DELETE = 'delete',
|
|
13
|
+
ARRAY_MUTATION = 'array mutation'
|
|
14
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { observe, Observer } from 'core/observer'
|
|
2
|
+
import { def, isArray, isPrimitive, warn, toRawType } from 'core/util'
|
|
3
|
+
import type { Ref, UnwrapRefSimple, RawSymbol } from './ref'
|
|
4
|
+
|
|
5
|
+
export const enum ReactiveFlags {
|
|
6
|
+
SKIP = '__v_skip',
|
|
7
|
+
IS_READONLY = '__v_isReadonly',
|
|
8
|
+
IS_SHALLOW = '__v_isShallow',
|
|
9
|
+
RAW = '__v_raw'
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface Target {
|
|
13
|
+
__ob__?: Observer
|
|
14
|
+
[ReactiveFlags.SKIP]?: boolean
|
|
15
|
+
[ReactiveFlags.IS_READONLY]?: boolean
|
|
16
|
+
[ReactiveFlags.IS_SHALLOW]?: boolean
|
|
17
|
+
[ReactiveFlags.RAW]?: any
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// only unwrap nested ref
|
|
21
|
+
export type UnwrapNestedRefs<T> = T extends Ref ? T : UnwrapRefSimple<T>
|
|
22
|
+
|
|
23
|
+
export function reactive<T extends object>(target: T): UnwrapNestedRefs<T>
|
|
24
|
+
export function reactive(target: object) {
|
|
25
|
+
makeReactive(target, false)
|
|
26
|
+
return target
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export declare const ShallowReactiveMarker: unique symbol
|
|
30
|
+
|
|
31
|
+
export type ShallowReactive<T> = T & { [ShallowReactiveMarker]?: true }
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Return a shallowly-reactive copy of the original object, where only the root
|
|
35
|
+
* level properties are reactive. It also does not auto-unwrap refs (even at the
|
|
36
|
+
* root level).
|
|
37
|
+
*/
|
|
38
|
+
export function shallowReactive<T extends object>(
|
|
39
|
+
target: T
|
|
40
|
+
): ShallowReactive<T> {
|
|
41
|
+
makeReactive(target, true)
|
|
42
|
+
def(target, ReactiveFlags.IS_SHALLOW, true)
|
|
43
|
+
return target
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function makeReactive(target: any, shallow: boolean) {
|
|
47
|
+
// if trying to observe a readonly proxy, return the readonly version.
|
|
48
|
+
if (!isReadonly(target)) {
|
|
49
|
+
if (__DEV__) {
|
|
50
|
+
if (isArray(target)) {
|
|
51
|
+
warn(
|
|
52
|
+
`Avoid using Array as root value for ${
|
|
53
|
+
shallow ? `shallowReactive()` : `reactive()`
|
|
54
|
+
} as it cannot be tracked in watch() or watchEffect(). Use ${
|
|
55
|
+
shallow ? `shallowRef()` : `ref()`
|
|
56
|
+
} instead. This is a Vue-2-only limitation.`
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
const existingOb = target && target.__ob__
|
|
60
|
+
if (existingOb && existingOb.shallow !== shallow) {
|
|
61
|
+
warn(
|
|
62
|
+
`Target is already a ${
|
|
63
|
+
existingOb.shallow ? `` : `non-`
|
|
64
|
+
}shallow reactive object, and cannot be converted to ${
|
|
65
|
+
shallow ? `` : `non-`
|
|
66
|
+
}shallow.`
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const ob = observe(target, shallow)
|
|
71
|
+
if (__DEV__ && !ob) {
|
|
72
|
+
if (target == null || isPrimitive(target)) {
|
|
73
|
+
warn(`value cannot be made reactive: ${String(target)}`)
|
|
74
|
+
}
|
|
75
|
+
if (isCollectionType(target)) {
|
|
76
|
+
warn(
|
|
77
|
+
`Vue 2 does not support reactive collection types such as Map or Set.`
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function isReactive(value: unknown): boolean {
|
|
85
|
+
if (isReadonly(value)) {
|
|
86
|
+
return isReactive((value as Target)[ReactiveFlags.RAW])
|
|
87
|
+
}
|
|
88
|
+
return !!(value && (value as Target).__ob__)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function isShallow(value: unknown): boolean {
|
|
92
|
+
return !!(value && (value as Target).__v_isShallow)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function isReadonly(value: unknown): boolean {
|
|
96
|
+
return !!(value && (value as Target).__v_isReadonly)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function isProxy(value: unknown): boolean {
|
|
100
|
+
return isReactive(value) || isReadonly(value)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function toRaw<T>(observed: T): T {
|
|
104
|
+
const raw = observed && (observed as Target)[ReactiveFlags.RAW]
|
|
105
|
+
return raw ? toRaw(raw) : observed
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function markRaw<T extends object>(
|
|
109
|
+
value: T
|
|
110
|
+
): T & { [RawSymbol]?: true } {
|
|
111
|
+
def(value, ReactiveFlags.SKIP, true)
|
|
112
|
+
return value
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* @internal
|
|
117
|
+
*/
|
|
118
|
+
export function isCollectionType(value: unknown): boolean {
|
|
119
|
+
const type = toRawType(value)
|
|
120
|
+
return (
|
|
121
|
+
type === 'Map' || type === 'WeakMap' || type === 'Set' || type === 'WeakSet'
|
|
122
|
+
)
|
|
123
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { def, warn, isPlainObject, isArray } from 'core/util'
|
|
2
|
+
import {
|
|
3
|
+
isCollectionType,
|
|
4
|
+
isReadonly,
|
|
5
|
+
isShallow,
|
|
6
|
+
ReactiveFlags,
|
|
7
|
+
UnwrapNestedRefs
|
|
8
|
+
} from './reactive'
|
|
9
|
+
import { isRef, Ref, RefFlag } from './ref'
|
|
10
|
+
|
|
11
|
+
type Primitive = string | number | boolean | bigint | symbol | undefined | null
|
|
12
|
+
type Builtin = Primitive | Function | Date | Error | RegExp
|
|
13
|
+
export type DeepReadonly<T> = T extends Builtin
|
|
14
|
+
? T
|
|
15
|
+
: T extends Map<infer K, infer V>
|
|
16
|
+
? ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>>
|
|
17
|
+
: T extends ReadonlyMap<infer K, infer V>
|
|
18
|
+
? ReadonlyMap<DeepReadonly<K>, DeepReadonly<V>>
|
|
19
|
+
: T extends WeakMap<infer K, infer V>
|
|
20
|
+
? WeakMap<DeepReadonly<K>, DeepReadonly<V>>
|
|
21
|
+
: T extends Set<infer U>
|
|
22
|
+
? ReadonlySet<DeepReadonly<U>>
|
|
23
|
+
: T extends ReadonlySet<infer U>
|
|
24
|
+
? ReadonlySet<DeepReadonly<U>>
|
|
25
|
+
: T extends WeakSet<infer U>
|
|
26
|
+
? WeakSet<DeepReadonly<U>>
|
|
27
|
+
: T extends Promise<infer U>
|
|
28
|
+
? Promise<DeepReadonly<U>>
|
|
29
|
+
: T extends Ref<infer U>
|
|
30
|
+
? Readonly<Ref<DeepReadonly<U>>>
|
|
31
|
+
: T extends {}
|
|
32
|
+
? { readonly [K in keyof T]: DeepReadonly<T[K]> }
|
|
33
|
+
: Readonly<T>
|
|
34
|
+
|
|
35
|
+
const rawToReadonlyFlag = `__v_rawToReadonly`
|
|
36
|
+
const rawToShallowReadonlyFlag = `__v_rawToShallowReadonly`
|
|
37
|
+
|
|
38
|
+
export function readonly<T extends object>(
|
|
39
|
+
target: T
|
|
40
|
+
): DeepReadonly<UnwrapNestedRefs<T>> {
|
|
41
|
+
return createReadonly(target, false)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function createReadonly(target: any, shallow: boolean) {
|
|
45
|
+
if (!isPlainObject(target)) {
|
|
46
|
+
if (__DEV__) {
|
|
47
|
+
if (isArray(target)) {
|
|
48
|
+
warn(`Vue 2 does not support readonly arrays.`)
|
|
49
|
+
} else if (isCollectionType(target)) {
|
|
50
|
+
warn(
|
|
51
|
+
`Vue 2 does not support readonly collection types such as Map or Set.`
|
|
52
|
+
)
|
|
53
|
+
} else {
|
|
54
|
+
warn(`value cannot be made readonly: ${typeof target}`)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return target as any
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// already a readonly object
|
|
61
|
+
if (isReadonly(target)) {
|
|
62
|
+
return target as any
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// already has a readonly proxy
|
|
66
|
+
const existingFlag = shallow ? rawToShallowReadonlyFlag : rawToReadonlyFlag
|
|
67
|
+
const existingProxy = target[existingFlag]
|
|
68
|
+
if (existingProxy) {
|
|
69
|
+
return existingProxy
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const proxy = {}
|
|
73
|
+
def(target, existingFlag, proxy)
|
|
74
|
+
|
|
75
|
+
def(proxy, ReactiveFlags.IS_READONLY, true)
|
|
76
|
+
def(proxy, ReactiveFlags.RAW, target)
|
|
77
|
+
|
|
78
|
+
if (isRef(target)) {
|
|
79
|
+
def(proxy, RefFlag, true)
|
|
80
|
+
}
|
|
81
|
+
if (shallow || isShallow(target)) {
|
|
82
|
+
def(proxy, ReactiveFlags.IS_SHALLOW, true)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const keys = Object.keys(target)
|
|
86
|
+
for (let i = 0; i < keys.length; i++) {
|
|
87
|
+
defineReadonlyProperty(proxy, target, keys[i], shallow)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return proxy as any
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function defineReadonlyProperty(
|
|
94
|
+
proxy: any,
|
|
95
|
+
target: any,
|
|
96
|
+
key: string,
|
|
97
|
+
shallow: boolean
|
|
98
|
+
) {
|
|
99
|
+
Object.defineProperty(proxy, key, {
|
|
100
|
+
enumerable: true,
|
|
101
|
+
configurable: true,
|
|
102
|
+
get() {
|
|
103
|
+
const val = target[key]
|
|
104
|
+
return shallow || !isPlainObject(val) ? val : readonly(val)
|
|
105
|
+
},
|
|
106
|
+
set() {
|
|
107
|
+
__DEV__ &&
|
|
108
|
+
warn(`Set operation on key "${key}" failed: target is readonly.`)
|
|
109
|
+
}
|
|
110
|
+
})
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Returns a reactive-copy of the original object, where only the root level
|
|
115
|
+
* properties are readonly, and does NOT unwrap refs nor recursively convert
|
|
116
|
+
* returned properties.
|
|
117
|
+
* This is used for creating the props proxy object for stateful components.
|
|
118
|
+
*/
|
|
119
|
+
export function shallowReadonly<T extends object>(target: T): Readonly<T> {
|
|
120
|
+
return createReadonly(target, true)
|
|
121
|
+
}
|