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.
Files changed (262) hide show
  1. package/README.md +17 -295
  2. package/compiler-sfc/index.d.ts +1 -0
  3. package/compiler-sfc/index.js +1 -0
  4. package/compiler-sfc/index.mjs +1 -0
  5. package/compiler-sfc/package.json +5 -0
  6. package/dist/vue.common.dev.js +11481 -11946
  7. package/dist/vue.common.prod.js +8 -3
  8. package/dist/vue.esm.browser.js +11321 -12011
  9. package/dist/vue.esm.browser.min.js +8 -3
  10. package/dist/vue.esm.js +11476 -11984
  11. package/dist/vue.js +11484 -11949
  12. package/dist/vue.min.js +8 -3
  13. package/dist/vue.runtime.common.dev.js +8427 -8421
  14. package/dist/vue.runtime.common.prod.js +8 -3
  15. package/dist/vue.runtime.esm.js +8436 -8454
  16. package/dist/vue.runtime.js +8430 -8424
  17. package/dist/vue.runtime.min.js +8 -3
  18. package/package.json +88 -111
  19. package/packages/compiler-sfc/dist/compiler-sfc.js +7 -0
  20. package/packages/compiler-sfc/node_modules/.bin/parser +17 -0
  21. package/packages/compiler-sfc/node_modules/.bin/sass +17 -0
  22. package/packages/compiler-sfc/package.json +30 -0
  23. package/src/compiler/{codeframe.js → codeframe.ts} +9 -7
  24. package/src/compiler/codegen/{events.js → events.ts} +21 -41
  25. package/src/compiler/codegen/{index.js → index.ts} +146 -136
  26. package/src/compiler/{create-compiler.js → create-compiler.ts} +26 -18
  27. package/src/compiler/directives/bind.ts +9 -0
  28. package/src/compiler/directives/{index.js → index.ts} +0 -2
  29. package/src/compiler/directives/{model.js → model.ts} +15 -18
  30. package/src/compiler/directives/{on.js → on.ts} +3 -4
  31. package/src/compiler/{error-detector.js → error-detector.ts} +61 -31
  32. package/src/compiler/{helpers.js → helpers.ts} +73 -61
  33. package/src/compiler/{index.js → index.ts} +2 -3
  34. package/src/compiler/{optimizer.js → optimizer.ts} +30 -23
  35. package/src/compiler/parser/{entity-decoder.js → entity-decoder.ts} +1 -3
  36. package/src/compiler/parser/{filter-parser.js → filter-parser.ts} +43 -24
  37. package/src/compiler/parser/{html-parser.js → html-parser.ts} +50 -29
  38. package/src/compiler/parser/{index.js → index.ts} +190 -172
  39. package/src/compiler/parser/{text-parser.js → text-parser.ts} +8 -9
  40. package/src/compiler/{to-function.js → to-function.ts} +27 -22
  41. package/src/core/components/{index.js → index.ts} +0 -0
  42. package/src/core/components/{keep-alive.js → keep-alive.ts} +42 -30
  43. package/src/core/{config.js → config.ts} +28 -30
  44. package/src/core/global-api/{assets.js → assets.ts} +8 -7
  45. package/src/core/global-api/{extend.js → extend.ts} +10 -13
  46. package/src/core/global-api/{index.js → index.ts} +4 -5
  47. package/src/core/global-api/{mixin.js → mixin.ts} +2 -3
  48. package/src/core/global-api/use.ts +23 -0
  49. package/src/core/{index.js → index.ts} +1 -1
  50. package/src/core/instance/{events.js → events.ts} +41 -24
  51. package/src/core/instance/{index.js → index.ts} +9 -5
  52. package/src/core/instance/{init.js → init.ts} +26 -15
  53. package/src/core/instance/inject.ts +72 -0
  54. package/src/core/instance/{lifecycle.js → lifecycle.ts} +86 -44
  55. package/src/core/instance/{proxy.js → proxy.ts} +29 -24
  56. package/src/core/instance/render-helpers/{bind-dynamic-keys.js → bind-dynamic-keys.ts} +6 -5
  57. package/src/core/instance/render-helpers/{bind-object-listeners.js → bind-object-listeners.ts} +4 -8
  58. package/src/core/instance/render-helpers/{bind-object-props.js → bind-object-props.ts} +12 -17
  59. package/src/core/instance/render-helpers/{check-keycodes.js → check-keycodes.ts} +5 -7
  60. package/src/core/instance/render-helpers/{index.js → index.ts} +1 -3
  61. package/src/core/instance/render-helpers/{render-list.js → render-list.ts} +12 -13
  62. package/src/core/instance/render-helpers/{render-slot.js → render-slot.ts} +10 -11
  63. package/src/core/instance/render-helpers/{render-static.js → render-static.ts} +7 -10
  64. package/src/core/instance/render-helpers/{resolve-filter.js → resolve-filter.ts} +1 -3
  65. package/src/core/instance/render-helpers/{resolve-scoped-slots.js → resolve-scoped-slots.ts} +11 -8
  66. package/src/core/instance/render-helpers/{resolve-slots.js → resolve-slots.ts} +12 -11
  67. package/src/core/instance/{render.js → render.ts} +66 -29
  68. package/src/core/instance/{state.js → state.ts} +100 -83
  69. package/src/core/observer/{array.js → array.ts} +11 -2
  70. package/src/core/observer/{dep.js → dep.ts} +37 -15
  71. package/src/core/observer/{index.js → index.ts} +137 -71
  72. package/src/core/observer/{scheduler.js → scheduler.ts} +42 -43
  73. package/src/core/observer/{traverse.js → traverse.ts} +10 -7
  74. package/src/core/observer/{watcher.js → watcher.ts} +88 -60
  75. package/src/core/util/{debug.js → debug.ts} +38 -34
  76. package/src/core/util/{env.js → env.ts} +27 -30
  77. package/src/core/util/{error.js → error.ts} +12 -14
  78. package/src/core/util/{index.js → index.ts} +0 -2
  79. package/src/core/util/{lang.js → lang.ts} +6 -7
  80. package/src/core/util/{next-tick.js → next-tick.ts} +16 -10
  81. package/src/core/util/{options.js → options.ts} +119 -114
  82. package/src/core/util/{perf.js → perf.ts} +5 -1
  83. package/src/core/util/{props.js → props.ts} +54 -50
  84. package/src/core/vdom/{create-component.js → create-component.ts} +51 -50
  85. package/src/core/vdom/{create-element.js → create-element.ts} +49 -43
  86. package/src/core/vdom/{create-functional-component.js → create-functional-component.ts} +52 -27
  87. package/src/core/vdom/helpers/{extract-props.js → extract-props.ts} +18 -18
  88. package/src/core/vdom/helpers/{get-first-component-child.js → get-first-component-child.ts} +6 -5
  89. package/src/core/vdom/helpers/{index.js → index.ts} +0 -2
  90. package/src/core/vdom/helpers/is-async-placeholder.ts +6 -0
  91. package/src/core/vdom/helpers/{merge-hook.js → merge-hook.ts} +7 -5
  92. package/src/core/vdom/helpers/{normalize-children.js → normalize-children.ts} +26 -16
  93. package/src/core/vdom/helpers/{normalize-scoped-slots.js → normalize-scoped-slots.ts} +23 -17
  94. package/src/core/vdom/helpers/{resolve-async-component.js → resolve-async-component.ts} +29 -37
  95. package/src/core/vdom/helpers/update-listeners.ts +101 -0
  96. package/src/core/vdom/modules/{directives.js → directives.ts} +20 -14
  97. package/src/core/vdom/modules/index.ts +4 -0
  98. package/src/core/vdom/modules/template-ref.ts +96 -0
  99. package/src/core/vdom/{patch.js → patch.ts} +239 -138
  100. package/src/core/vdom/{vnode.js → vnode.ts} +36 -31
  101. package/src/global.d.ts +15 -0
  102. package/src/platforms/web/compiler/directives/html.ts +8 -0
  103. package/src/platforms/web/compiler/directives/{index.js → index.ts} +0 -0
  104. package/src/platforms/web/compiler/directives/{model.js → model.ts} +47 -41
  105. package/src/platforms/web/compiler/directives/{text.js → text.ts} +2 -3
  106. package/src/platforms/web/compiler/{index.js → index.ts} +0 -2
  107. package/src/platforms/web/compiler/modules/{class.js → class.ts} +10 -15
  108. package/src/platforms/web/compiler/modules/{index.js → index.ts} +1 -5
  109. package/src/platforms/web/compiler/modules/{model.js → model.ts} +6 -11
  110. package/src/platforms/web/compiler/modules/{style.js → style.ts} +9 -14
  111. package/src/platforms/web/compiler/{options.js → options.ts} +1 -2
  112. package/src/platforms/web/compiler/{util.js → util.ts} +5 -7
  113. package/src/platforms/web/entry-compiler-sfc.ts +1 -0
  114. package/src/platforms/web/{entry-compiler.js → entry-compiler.ts} +1 -3
  115. package/src/platforms/web/{entry-runtime.js → entry-runtime-esm.ts} +2 -2
  116. package/src/platforms/web/entry-runtime-with-compiler-esm.ts +5 -0
  117. package/src/platforms/web/entry-runtime-with-compiler.ts +10 -0
  118. package/src/platforms/web/entry-runtime.ts +7 -0
  119. package/src/platforms/web/runtime/{class-util.js → class-util.ts} +2 -4
  120. package/src/platforms/web/runtime/components/{index.js → index.ts} +0 -0
  121. package/src/platforms/web/runtime/components/{transition-group.js → transition-group.ts} +59 -46
  122. package/src/platforms/web/runtime/components/{transition.js → transition.ts} +43 -36
  123. package/src/platforms/web/runtime/directives/{index.js → index.ts} +0 -0
  124. package/src/platforms/web/runtime/directives/{model.js → model.ts} +22 -21
  125. package/src/platforms/web/runtime/directives/{show.js → show.ts} +11 -10
  126. package/src/platforms/web/runtime/{index.js → index.ts} +9 -10
  127. package/src/platforms/web/runtime/modules/{attrs.js → attrs.ts} +12 -16
  128. package/src/platforms/web/runtime/modules/{class.js → class.ts} +7 -18
  129. package/src/platforms/web/runtime/modules/{dom-props.js → dom-props.ts} +24 -17
  130. package/src/platforms/web/runtime/modules/{events.js → events.ts} +22 -15
  131. package/src/platforms/web/runtime/modules/{index.js → index.ts} +1 -8
  132. package/src/platforms/web/runtime/modules/{style.js → style.ts} +24 -13
  133. package/src/platforms/web/runtime/modules/{transition.js → transition.ts} +61 -63
  134. package/src/platforms/web/runtime/node-ops.ts +66 -0
  135. package/src/platforms/web/runtime/{patch.js → patch.ts} +0 -2
  136. package/src/platforms/web/runtime/{transition-util.js → transition-util.ts} +63 -38
  137. package/src/platforms/web/{entry-runtime-with-compiler.js → runtime-with-compiler.ts} +28 -19
  138. package/src/platforms/web/util/{attrs.js → attrs.ts} +18 -14
  139. package/src/platforms/web/util/{class.js → class.ts} +23 -21
  140. package/src/platforms/web/util/{compat.js → compat.ts} +4 -4
  141. package/src/platforms/web/util/{element.js → element.ts} +21 -22
  142. package/src/platforms/web/util/{index.js → index.ts} +2 -6
  143. package/src/platforms/web/util/{style.js → style.ts} +12 -12
  144. package/src/sfc/{parser.js → parser.ts} +18 -15
  145. package/src/shared/{constants.js → constants.ts} +2 -6
  146. package/src/shared/{util.js → util.ts} +78 -55
  147. package/src/types/compiler.ts +224 -0
  148. package/src/types/component.ts +209 -0
  149. package/src/types/global-api.ts +37 -0
  150. package/src/types/modules.d.ts +15 -0
  151. package/src/types/options.ts +120 -0
  152. package/src/types/ssr.ts +27 -0
  153. package/src/types/utils.ts +3 -0
  154. package/src/types/vnode.ts +127 -0
  155. package/src/v3/apiInject.ts +66 -0
  156. package/src/v3/apiLifecycle.ts +53 -0
  157. package/src/v3/apiSetup.ts +161 -0
  158. package/src/v3/apiWatch.ts +355 -0
  159. package/src/v3/currentInstance.ts +23 -0
  160. package/src/v3/debug.ts +21 -0
  161. package/src/v3/h.ts +18 -0
  162. package/src/v3/index.ts +77 -0
  163. package/src/v3/reactivity/computed.ts +100 -0
  164. package/src/v3/reactivity/effect.ts +20 -0
  165. package/src/v3/reactivity/effectScope.ts +134 -0
  166. package/src/v3/reactivity/operations.ts +14 -0
  167. package/src/v3/reactivity/reactive.ts +123 -0
  168. package/src/v3/reactivity/readonly.ts +121 -0
  169. package/src/v3/reactivity/ref.ts +249 -0
  170. package/types/index.d.ts +10 -13
  171. package/types/options.d.ts +265 -132
  172. package/types/plugin.d.ts +4 -4
  173. package/types/umd.d.ts +47 -27
  174. package/types/v3-generated.d.ts +389 -0
  175. package/types/v3.d.ts +16 -0
  176. package/types/vnode.d.ts +70 -57
  177. package/types/vue.d.ts +292 -88
  178. package/dist/README.md +0 -122
  179. package/src/compiler/directives/bind.js +0 -11
  180. package/src/core/global-api/use.js +0 -23
  181. package/src/core/instance/inject.js +0 -73
  182. package/src/core/vdom/helpers/is-async-placeholder.js +0 -5
  183. package/src/core/vdom/helpers/update-listeners.js +0 -95
  184. package/src/core/vdom/modules/index.js +0 -7
  185. package/src/core/vdom/modules/ref.js +0 -45
  186. package/src/platforms/web/compiler/directives/html.js +0 -9
  187. package/src/platforms/web/entry-server-basic-renderer.js +0 -13
  188. package/src/platforms/web/entry-server-renderer.js +0 -27
  189. package/src/platforms/web/runtime/node-ops.js +0 -59
  190. package/src/platforms/web/server/compiler.js +0 -11
  191. package/src/platforms/web/server/directives/index.js +0 -7
  192. package/src/platforms/web/server/directives/model.js +0 -44
  193. package/src/platforms/web/server/directives/show.js +0 -12
  194. package/src/platforms/web/server/modules/attrs.js +0 -67
  195. package/src/platforms/web/server/modules/class.js +0 -11
  196. package/src/platforms/web/server/modules/dom-props.js +0 -50
  197. package/src/platforms/web/server/modules/index.js +0 -11
  198. package/src/platforms/web/server/modules/style.js +0 -41
  199. package/src/platforms/web/server/util.js +0 -101
  200. package/src/platforms/weex/compiler/directives/index.js +0 -5
  201. package/src/platforms/weex/compiler/directives/model.js +0 -33
  202. package/src/platforms/weex/compiler/index.js +0 -52
  203. package/src/platforms/weex/compiler/modules/append.js +0 -27
  204. package/src/platforms/weex/compiler/modules/class.js +0 -74
  205. package/src/platforms/weex/compiler/modules/index.js +0 -13
  206. package/src/platforms/weex/compiler/modules/props.js +0 -37
  207. package/src/platforms/weex/compiler/modules/recycle-list/component-root.js +0 -13
  208. package/src/platforms/weex/compiler/modules/recycle-list/component.js +0 -16
  209. package/src/platforms/weex/compiler/modules/recycle-list/index.js +0 -60
  210. package/src/platforms/weex/compiler/modules/recycle-list/recycle-list.js +0 -50
  211. package/src/platforms/weex/compiler/modules/recycle-list/text.js +0 -23
  212. package/src/platforms/weex/compiler/modules/recycle-list/v-bind.js +0 -21
  213. package/src/platforms/weex/compiler/modules/recycle-list/v-for.js +0 -33
  214. package/src/platforms/weex/compiler/modules/recycle-list/v-if.js +0 -63
  215. package/src/platforms/weex/compiler/modules/recycle-list/v-on.js +0 -25
  216. package/src/platforms/weex/compiler/modules/recycle-list/v-once.js +0 -19
  217. package/src/platforms/weex/compiler/modules/style.js +0 -87
  218. package/src/platforms/weex/entry-compiler.js +0 -2
  219. package/src/platforms/weex/entry-framework.js +0 -187
  220. package/src/platforms/weex/entry-runtime-factory.js +0 -6
  221. package/src/platforms/weex/runtime/components/index.js +0 -9
  222. package/src/platforms/weex/runtime/components/richtext.js +0 -82
  223. package/src/platforms/weex/runtime/components/transition-group.js +0 -148
  224. package/src/platforms/weex/runtime/components/transition.js +0 -9
  225. package/src/platforms/weex/runtime/directives/index.js +0 -2
  226. package/src/platforms/weex/runtime/index.js +0 -42
  227. package/src/platforms/weex/runtime/modules/attrs.js +0 -44
  228. package/src/platforms/weex/runtime/modules/class.js +0 -76
  229. package/src/platforms/weex/runtime/modules/events.js +0 -54
  230. package/src/platforms/weex/runtime/modules/index.js +0 -13
  231. package/src/platforms/weex/runtime/modules/style.js +0 -84
  232. package/src/platforms/weex/runtime/modules/transition.js +0 -270
  233. package/src/platforms/weex/runtime/node-ops.js +0 -91
  234. package/src/platforms/weex/runtime/patch.js +0 -16
  235. package/src/platforms/weex/runtime/recycle-list/render-component-template.js +0 -34
  236. package/src/platforms/weex/runtime/recycle-list/virtual-component.js +0 -136
  237. package/src/platforms/weex/runtime/text-node.js +0 -9
  238. package/src/platforms/weex/util/element.js +0 -52
  239. package/src/platforms/weex/util/index.js +0 -40
  240. package/src/platforms/weex/util/parser.js +0 -60
  241. package/src/server/bundle-renderer/create-bundle-renderer.js +0 -151
  242. package/src/server/bundle-renderer/create-bundle-runner.js +0 -150
  243. package/src/server/bundle-renderer/source-map-support.js +0 -45
  244. package/src/server/create-basic-renderer.js +0 -37
  245. package/src/server/create-renderer.js +0 -152
  246. package/src/server/optimizing-compiler/codegen.js +0 -264
  247. package/src/server/optimizing-compiler/index.js +0 -20
  248. package/src/server/optimizing-compiler/modules.js +0 -124
  249. package/src/server/optimizing-compiler/optimizer.js +0 -141
  250. package/src/server/optimizing-compiler/runtime-helpers.js +0 -150
  251. package/src/server/render-context.js +0 -130
  252. package/src/server/render-stream.js +0 -95
  253. package/src/server/render.js +0 -437
  254. package/src/server/template-renderer/create-async-file-mapper.js +0 -57
  255. package/src/server/template-renderer/index.js +0 -277
  256. package/src/server/template-renderer/parse-template.js +0 -42
  257. package/src/server/template-renderer/template-stream.js +0 -82
  258. package/src/server/util.js +0 -18
  259. package/src/server/webpack-plugin/client.js +0 -65
  260. package/src/server/webpack-plugin/server.js +0 -66
  261. package/src/server/webpack-plugin/util.js +0 -34
  262. package/src/server/write.js +0 -50
@@ -1,49 +1,71 @@
1
- /* @flow */
2
-
3
- import type Watcher from './watcher'
4
1
  import { remove } from '../util/index'
5
2
  import config from '../config'
3
+ import { DebuggerOptions, DebuggerEventExtraInfo } from 'v3'
6
4
 
7
5
  let uid = 0
8
6
 
7
+ /**
8
+ * @internal
9
+ */
10
+ export interface DepTarget extends DebuggerOptions {
11
+ id: number
12
+ addDep(dep: Dep): void
13
+ update(): void
14
+ }
15
+
9
16
  /**
10
17
  * A dep is an observable that can have multiple
11
18
  * directives subscribing to it.
19
+ * @internal
12
20
  */
13
21
  export default class Dep {
14
- static target: ?Watcher;
15
- id: number;
16
- subs: Array<Watcher>;
22
+ static target?: DepTarget | null
23
+ id: number
24
+ subs: Array<DepTarget>
17
25
 
18
- constructor () {
26
+ constructor() {
19
27
  this.id = uid++
20
28
  this.subs = []
21
29
  }
22
30
 
23
- addSub (sub: Watcher) {
31
+ addSub(sub: DepTarget) {
24
32
  this.subs.push(sub)
25
33
  }
26
34
 
27
- removeSub (sub: Watcher) {
35
+ removeSub(sub: DepTarget) {
28
36
  remove(this.subs, sub)
29
37
  }
30
38
 
31
- depend () {
39
+ depend(info?: DebuggerEventExtraInfo) {
32
40
  if (Dep.target) {
33
41
  Dep.target.addDep(this)
42
+ if (__DEV__ && info && Dep.target.onTrack) {
43
+ Dep.target.onTrack({
44
+ effect: Dep.target,
45
+ ...info
46
+ })
47
+ }
34
48
  }
35
49
  }
36
50
 
37
- notify () {
51
+ notify(info?: DebuggerEventExtraInfo) {
38
52
  // stabilize the subscriber list first
39
53
  const subs = this.subs.slice()
40
- if (process.env.NODE_ENV !== 'production' && !config.async) {
54
+ if (__DEV__ && !config.async) {
41
55
  // subs aren't sorted in scheduler if not running async
42
56
  // we need to sort them now to make sure they fire in correct
43
57
  // order
44
58
  subs.sort((a, b) => a.id - b.id)
45
59
  }
46
60
  for (let i = 0, l = subs.length; i < l; i++) {
61
+ if (__DEV__ && info) {
62
+ const sub = subs[i]
63
+ sub.onTrigger &&
64
+ sub.onTrigger({
65
+ effect: subs[i],
66
+ ...info
67
+ })
68
+ }
47
69
  subs[i].update()
48
70
  }
49
71
  }
@@ -53,14 +75,14 @@ export default class Dep {
53
75
  // This is globally unique because only one watcher
54
76
  // can be evaluated at a time.
55
77
  Dep.target = null
56
- const targetStack = []
78
+ const targetStack: Array<DepTarget | null | undefined> = []
57
79
 
58
- export function pushTarget (target: ?Watcher) {
80
+ export function pushTarget(target?: DepTarget | null) {
59
81
  targetStack.push(target)
60
82
  Dep.target = target
61
83
  }
62
84
 
63
- export function popTarget () {
85
+ export function popTarget() {
64
86
  targetStack.pop()
65
87
  Dep.target = targetStack[targetStack.length - 1]
66
88
  }
@@ -1,5 +1,3 @@
1
- /* @flow */
2
-
3
1
  import Dep from './dep'
4
2
  import VNode from '../vdom/vnode'
5
3
  import { arrayMethods } from './array'
@@ -7,24 +5,29 @@ import {
7
5
  def,
8
6
  warn,
9
7
  hasOwn,
8
+ isArray,
10
9
  hasProto,
11
10
  isObject,
12
11
  isPlainObject,
13
12
  isPrimitive,
14
13
  isUndef,
15
14
  isValidArrayIndex,
16
- isServerRendering
15
+ isServerRendering,
16
+ hasChanged
17
17
  } from '../util/index'
18
+ import { isReadonly, isRef, TrackOpTypes, TriggerOpTypes } from '../../v3'
18
19
 
19
20
  const arrayKeys = Object.getOwnPropertyNames(arrayMethods)
20
21
 
22
+ const NO_INIITIAL_VALUE = {}
23
+
21
24
  /**
22
25
  * In some cases we may want to disable observation inside a component's
23
26
  * update computation.
24
27
  */
25
28
  export let shouldObserve: boolean = true
26
29
 
27
- export function toggleObserving (value: boolean) {
30
+ export function toggleObserving(value: boolean) {
28
31
  shouldObserve = value
29
32
  }
30
33
 
@@ -35,24 +38,25 @@ export function toggleObserving (value: boolean) {
35
38
  * collect dependencies and dispatch updates.
36
39
  */
37
40
  export class Observer {
38
- value: any;
39
- dep: Dep;
40
- vmCount: number; // number of vms that have this object as root $data
41
+ dep: Dep
42
+ vmCount: number // number of vms that have this object as root $data
41
43
 
42
- constructor (value: any) {
43
- this.value = value
44
+ constructor(public value: any, public shallow = false) {
45
+ // this.value = value
44
46
  this.dep = new Dep()
45
47
  this.vmCount = 0
46
48
  def(value, '__ob__', this)
47
- if (Array.isArray(value)) {
49
+ if (isArray(value)) {
48
50
  if (hasProto) {
49
51
  protoAugment(value, arrayMethods)
50
52
  } else {
51
53
  copyAugment(value, arrayMethods, arrayKeys)
52
54
  }
53
- this.observeArray(value)
55
+ if (!shallow) {
56
+ this.observeArray(value)
57
+ }
54
58
  } else {
55
- this.walk(value)
59
+ this.walk(value, shallow)
56
60
  }
57
61
  }
58
62
 
@@ -61,17 +65,18 @@ export class Observer {
61
65
  * getter/setters. This method should only be called when
62
66
  * value type is Object.
63
67
  */
64
- walk (obj: Object) {
68
+ walk(obj: object, shallow: boolean) {
65
69
  const keys = Object.keys(obj)
66
70
  for (let i = 0; i < keys.length; i++) {
67
- defineReactive(obj, keys[i])
71
+ const key = keys[i]
72
+ defineReactive(obj, key, NO_INIITIAL_VALUE, undefined, shallow)
68
73
  }
69
74
  }
70
75
 
71
76
  /**
72
77
  * Observe a list of Array items.
73
78
  */
74
- observeArray (items: Array<any>) {
79
+ observeArray(items: Array<any>) {
75
80
  for (let i = 0, l = items.length; i < l; i++) {
76
81
  observe(items[i])
77
82
  }
@@ -84,7 +89,7 @@ export class Observer {
84
89
  * Augment a target Object or Array by intercepting
85
90
  * the prototype chain using __proto__
86
91
  */
87
- function protoAugment (target, src: Object) {
92
+ function protoAugment(target, src: Object) {
88
93
  /* eslint-disable no-proto */
89
94
  target.__proto__ = src
90
95
  /* eslint-enable no-proto */
@@ -95,7 +100,7 @@ function protoAugment (target, src: Object) {
95
100
  * hidden properties.
96
101
  */
97
102
  /* istanbul ignore next */
98
- function copyAugment (target: Object, src: Object, keys: Array<string>) {
103
+ function copyAugment(target: Object, src: Object, keys: Array<string>) {
99
104
  for (let i = 0, l = keys.length; i < l; i++) {
100
105
  const key = keys[i]
101
106
  def(target, key, src[key])
@@ -107,8 +112,8 @@ function copyAugment (target: Object, src: Object, keys: Array<string>) {
107
112
  * returns the new observer if successfully observed,
108
113
  * or the existing observer if the value already has one.
109
114
  */
110
- export function observe (value: any, asRootData: ?boolean): Observer | void {
111
- if (!isObject(value) || value instanceof VNode) {
115
+ export function observe(value: any, shallow?: boolean): Observer | void {
116
+ if (!isObject(value) || isRef(value) || value instanceof VNode) {
112
117
  return
113
118
  }
114
119
  let ob: Observer | void
@@ -117,14 +122,11 @@ export function observe (value: any, asRootData: ?boolean): Observer | void {
117
122
  } else if (
118
123
  shouldObserve &&
119
124
  !isServerRendering() &&
120
- (Array.isArray(value) || isPlainObject(value)) &&
125
+ (isArray(value) || isPlainObject(value)) &&
121
126
  Object.isExtensible(value) &&
122
- !value._isVue
127
+ !value.__v_skip
123
128
  ) {
124
- ob = new Observer(value)
125
- }
126
- if (asRootData && ob) {
127
- ob.vmCount++
129
+ ob = new Observer(value, shallow)
128
130
  }
129
131
  return ob
130
132
  }
@@ -132,11 +134,11 @@ export function observe (value: any, asRootData: ?boolean): Observer | void {
132
134
  /**
133
135
  * Define a reactive property on an Object.
134
136
  */
135
- export function defineReactive (
136
- obj: Object,
137
+ export function defineReactive(
138
+ obj: object,
137
139
  key: string,
138
- val: any,
139
- customSetter?: ?Function,
140
+ val?: any,
141
+ customSetter?: Function | null,
140
142
  shallow?: boolean
141
143
  ) {
142
144
  const dep = new Dep()
@@ -149,7 +151,10 @@ export function defineReactive (
149
151
  // cater for pre-defined getter/setters
150
152
  const getter = property && property.get
151
153
  const setter = property && property.set
152
- if ((!getter || setter) && arguments.length === 2) {
154
+ if (
155
+ (!getter || setter) &&
156
+ (val === NO_INIITIAL_VALUE || arguments.length === 2)
157
+ ) {
153
158
  val = obj[key]
154
159
  }
155
160
 
@@ -157,40 +162,62 @@ export function defineReactive (
157
162
  Object.defineProperty(obj, key, {
158
163
  enumerable: true,
159
164
  configurable: true,
160
- get: function reactiveGetter () {
165
+ get: function reactiveGetter() {
161
166
  const value = getter ? getter.call(obj) : val
162
167
  if (Dep.target) {
163
- dep.depend()
168
+ if (__DEV__) {
169
+ dep.depend({
170
+ target: obj,
171
+ type: TrackOpTypes.GET,
172
+ key
173
+ })
174
+ } else {
175
+ dep.depend()
176
+ }
164
177
  if (childOb) {
165
178
  childOb.dep.depend()
166
- if (Array.isArray(value)) {
179
+ if (isArray(value)) {
167
180
  dependArray(value)
168
181
  }
169
182
  }
170
183
  }
171
- return value
184
+ return isRef(value) ? value.value : value
172
185
  },
173
- set: function reactiveSetter (newVal) {
186
+ set: function reactiveSetter(newVal) {
174
187
  const value = getter ? getter.call(obj) : val
175
- /* eslint-disable no-self-compare */
176
- if (newVal === value || (newVal !== newVal && value !== value)) {
188
+ if (!hasChanged(value, newVal)) {
177
189
  return
178
190
  }
179
- /* eslint-enable no-self-compare */
180
- if (process.env.NODE_ENV !== 'production' && customSetter) {
191
+ if (__DEV__ && customSetter) {
181
192
  customSetter()
182
193
  }
183
- // #7981: for accessor properties without setter
184
- if (getter && !setter) return
185
194
  if (setter) {
186
195
  setter.call(obj, newVal)
196
+ } else if (getter) {
197
+ // #7981: for accessor properties without setter
198
+ return
199
+ } else if (isRef(value) && !isRef(newVal)) {
200
+ value.value = newVal
201
+ return
187
202
  } else {
188
203
  val = newVal
189
204
  }
190
205
  childOb = !shallow && observe(newVal)
191
- dep.notify()
206
+ if (__DEV__) {
207
+ dep.notify({
208
+ type: TriggerOpTypes.SET,
209
+ target: obj,
210
+ key,
211
+ newValue: newVal,
212
+ oldValue: value
213
+ })
214
+ } else {
215
+ dep.notify()
216
+ }
192
217
  }
193
218
  })
219
+
220
+ return dep
194
221
  }
195
222
 
196
223
  /**
@@ -198,13 +225,23 @@ export function defineReactive (
198
225
  * triggers change notification if the property doesn't
199
226
  * already exist.
200
227
  */
201
- export function set (target: Array<any> | Object, key: any, val: any): any {
202
- if (process.env.NODE_ENV !== 'production' &&
203
- (isUndef(target) || isPrimitive(target))
204
- ) {
205
- warn(`Cannot set reactive property on undefined, null, or primitive value: ${(target: any)}`)
228
+ export function set<T>(array: T[], key: number, value: T): T
229
+ export function set<T>(object: object, key: string | number, value: T): T
230
+ export function set(
231
+ target: any[] | Record<string, any>,
232
+ key: any,
233
+ val: any
234
+ ): any {
235
+ if (__DEV__ && (isUndef(target) || isPrimitive(target))) {
236
+ warn(
237
+ `Cannot set reactive property on undefined, null, or primitive value: ${target}`
238
+ )
239
+ }
240
+ if (isReadonly(target)) {
241
+ __DEV__ && warn(`Set operation on key "${key}" failed: target is readonly.`)
242
+ return
206
243
  }
207
- if (Array.isArray(target) && isValidArrayIndex(key)) {
244
+ if (isArray(target) && isValidArrayIndex(key)) {
208
245
  target.length = Math.max(target.length, key)
209
246
  target.splice(key, 1, val)
210
247
  return val
@@ -213,12 +250,13 @@ export function set (target: Array<any> | Object, key: any, val: any): any {
213
250
  target[key] = val
214
251
  return val
215
252
  }
216
- const ob = (target: any).__ob__
217
- if (target._isVue || (ob && ob.vmCount)) {
218
- process.env.NODE_ENV !== 'production' && warn(
219
- 'Avoid adding reactive properties to a Vue instance or its root $data ' +
220
- 'at runtime - declare it upfront in the data option.'
221
- )
253
+ const ob = (target as any).__ob__
254
+ if ((target as any)._isVue || (ob && ob.vmCount)) {
255
+ __DEV__ &&
256
+ warn(
257
+ 'Avoid adding reactive properties to a Vue instance or its root $data ' +
258
+ 'at runtime - declare it upfront in the data option.'
259
+ )
222
260
  return val
223
261
  }
224
262
  if (!ob) {
@@ -226,29 +264,47 @@ export function set (target: Array<any> | Object, key: any, val: any): any {
226
264
  return val
227
265
  }
228
266
  defineReactive(ob.value, key, val)
229
- ob.dep.notify()
267
+ if (__DEV__) {
268
+ ob.dep.notify({
269
+ type: TriggerOpTypes.ADD,
270
+ target: target,
271
+ key,
272
+ newValue: val,
273
+ oldValue: undefined
274
+ })
275
+ } else {
276
+ ob.dep.notify()
277
+ }
230
278
  return val
231
279
  }
232
280
 
233
281
  /**
234
282
  * Delete a property and trigger change if necessary.
235
283
  */
236
- export function del (target: Array<any> | Object, key: any) {
237
- if (process.env.NODE_ENV !== 'production' &&
238
- (isUndef(target) || isPrimitive(target))
239
- ) {
240
- warn(`Cannot delete reactive property on undefined, null, or primitive value: ${(target: any)}`)
284
+ export function del<T>(array: T[], key: number): void
285
+ export function del(object: object, key: string | number): void
286
+ export function del(target: any[] | object, key: any) {
287
+ if (__DEV__ && (isUndef(target) || isPrimitive(target))) {
288
+ warn(
289
+ `Cannot delete reactive property on undefined, null, or primitive value: ${target}`
290
+ )
241
291
  }
242
- if (Array.isArray(target) && isValidArrayIndex(key)) {
292
+ if (isArray(target) && isValidArrayIndex(key)) {
243
293
  target.splice(key, 1)
244
294
  return
245
295
  }
246
- const ob = (target: any).__ob__
247
- if (target._isVue || (ob && ob.vmCount)) {
248
- process.env.NODE_ENV !== 'production' && warn(
249
- 'Avoid deleting properties on a Vue instance or its root $data ' +
250
- '- just set it to null.'
251
- )
296
+ const ob = (target as any).__ob__
297
+ if ((target as any)._isVue || (ob && ob.vmCount)) {
298
+ __DEV__ &&
299
+ warn(
300
+ 'Avoid deleting properties on a Vue instance or its root $data ' +
301
+ '- just set it to null.'
302
+ )
303
+ return
304
+ }
305
+ if (isReadonly(target)) {
306
+ __DEV__ &&
307
+ warn(`Delete operation on key "${key}" failed: target is readonly.`)
252
308
  return
253
309
  }
254
310
  if (!hasOwn(target, key)) {
@@ -258,18 +314,28 @@ export function del (target: Array<any> | Object, key: any) {
258
314
  if (!ob) {
259
315
  return
260
316
  }
261
- ob.dep.notify()
317
+ if (__DEV__) {
318
+ ob.dep.notify({
319
+ type: TriggerOpTypes.DELETE,
320
+ target: target,
321
+ key
322
+ })
323
+ } else {
324
+ ob.dep.notify()
325
+ }
262
326
  }
263
327
 
264
328
  /**
265
329
  * Collect dependencies on array elements when the array is touched, since
266
330
  * we cannot intercept array element access like property getters.
267
331
  */
268
- function dependArray (value: Array<any>) {
332
+ function dependArray(value: Array<any>) {
269
333
  for (let e, i = 0, l = value.length; i < l; i++) {
270
334
  e = value[i]
271
- e && e.__ob__ && e.__ob__.dep.depend()
272
- if (Array.isArray(e)) {
335
+ if (e && e.__ob__) {
336
+ e.__ob__.dep.depend()
337
+ }
338
+ if (isArray(e)) {
273
339
  dependArray(e)
274
340
  }
275
341
  }
@@ -1,22 +1,16 @@
1
- /* @flow */
2
-
3
1
  import type Watcher from './watcher'
4
2
  import config from '../config'
3
+ import Dep from './dep'
5
4
  import { callHook, activateChildComponent } from '../instance/lifecycle'
6
5
 
7
- import {
8
- warn,
9
- nextTick,
10
- devtools,
11
- inBrowser,
12
- isIE
13
- } from '../util/index'
6
+ import { warn, nextTick, devtools, inBrowser, isIE } from '../util/index'
7
+ import type { Component } from 'types/component'
14
8
 
15
9
  export const MAX_UPDATE_COUNT = 100
16
10
 
17
11
  const queue: Array<Watcher> = []
18
12
  const activatedChildren: Array<Component> = []
19
- let has: { [key: number]: ?true } = {}
13
+ let has: { [key: number]: true | undefined | null } = {}
20
14
  let circular: { [key: number]: number } = {}
21
15
  let waiting = false
22
16
  let flushing = false
@@ -25,10 +19,10 @@ let index = 0
25
19
  /**
26
20
  * Reset the scheduler's state.
27
21
  */
28
- function resetSchedulerState () {
22
+ function resetSchedulerState() {
29
23
  index = queue.length = activatedChildren.length = 0
30
24
  has = {}
31
- if (process.env.NODE_ENV !== 'production') {
25
+ if (__DEV__) {
32
26
  circular = {}
33
27
  }
34
28
  waiting = flushing = false
@@ -68,7 +62,7 @@ if (inBrowser && !isIE) {
68
62
  /**
69
63
  * Flush both queues and run the watchers.
70
64
  */
71
- function flushSchedulerQueue () {
65
+ function flushSchedulerQueue() {
72
66
  currentFlushTimestamp = getNow()
73
67
  flushing = true
74
68
  let watcher, id
@@ -94,15 +88,14 @@ function flushSchedulerQueue () {
94
88
  has[id] = null
95
89
  watcher.run()
96
90
  // in dev build, check and stop circular updates.
97
- if (process.env.NODE_ENV !== 'production' && has[id] != null) {
91
+ if (__DEV__ && has[id] != null) {
98
92
  circular[id] = (circular[id] || 0) + 1
99
93
  if (circular[id] > MAX_UPDATE_COUNT) {
100
94
  warn(
101
- 'You may have an infinite update loop ' + (
102
- watcher.user
95
+ 'You may have an infinite update loop ' +
96
+ (watcher.user
103
97
  ? `in watcher with expression "${watcher.expression}"`
104
- : `in a component render function.`
105
- ),
98
+ : `in a component render function.`),
106
99
  watcher.vm
107
100
  )
108
101
  break
@@ -127,12 +120,12 @@ function flushSchedulerQueue () {
127
120
  }
128
121
  }
129
122
 
130
- function callUpdatedHooks (queue) {
123
+ function callUpdatedHooks(queue: Watcher[]) {
131
124
  let i = queue.length
132
125
  while (i--) {
133
126
  const watcher = queue[i]
134
127
  const vm = watcher.vm
135
- if (vm._watcher === watcher && vm._isMounted && !vm._isDestroyed) {
128
+ if (vm && vm._watcher === watcher && vm._isMounted && !vm._isDestroyed) {
136
129
  callHook(vm, 'updated')
137
130
  }
138
131
  }
@@ -142,14 +135,14 @@ function callUpdatedHooks (queue) {
142
135
  * Queue a kept-alive component that was activated during patch.
143
136
  * The queue will be processed after the entire tree has been patched.
144
137
  */
145
- export function queueActivatedComponent (vm: Component) {
138
+ export function queueActivatedComponent(vm: Component) {
146
139
  // setting _inactive to false here so that a render function can
147
140
  // rely on checking whether it's in an inactive tree (e.g. router-view)
148
141
  vm._inactive = false
149
142
  activatedChildren.push(vm)
150
143
  }
151
144
 
152
- function callActivatedHooks (queue) {
145
+ function callActivatedHooks(queue) {
153
146
  for (let i = 0; i < queue.length; i++) {
154
147
  queue[i]._inactive = true
155
148
  activateChildComponent(queue[i], true /* true */)
@@ -161,30 +154,36 @@ function callActivatedHooks (queue) {
161
154
  * Jobs with duplicate IDs will be skipped unless it's
162
155
  * pushed when the queue is being flushed.
163
156
  */
164
- export function queueWatcher (watcher: Watcher) {
157
+ export function queueWatcher(watcher: Watcher) {
165
158
  const id = watcher.id
166
- if (has[id] == null) {
167
- has[id] = true
168
- if (!flushing) {
169
- queue.push(watcher)
170
- } else {
171
- // if already flushing, splice the watcher based on its id
172
- // if already past its id, it will be run next immediately.
173
- let i = queue.length - 1
174
- while (i > index && queue[i].id > watcher.id) {
175
- i--
176
- }
177
- queue.splice(i + 1, 0, watcher)
159
+ if (has[id] != null) {
160
+ return
161
+ }
162
+
163
+ if (watcher === Dep.target && watcher.noRecurse) {
164
+ return
165
+ }
166
+
167
+ has[id] = true
168
+ if (!flushing) {
169
+ queue.push(watcher)
170
+ } else {
171
+ // if already flushing, splice the watcher based on its id
172
+ // if already past its id, it will be run next immediately.
173
+ let i = queue.length - 1
174
+ while (i > index && queue[i].id > watcher.id) {
175
+ i--
178
176
  }
179
- // queue the flush
180
- if (!waiting) {
181
- waiting = true
177
+ queue.splice(i + 1, 0, watcher)
178
+ }
179
+ // queue the flush
180
+ if (!waiting) {
181
+ waiting = true
182
182
 
183
- if (process.env.NODE_ENV !== 'production' && !config.async) {
184
- flushSchedulerQueue()
185
- return
186
- }
187
- nextTick(flushSchedulerQueue)
183
+ if (__DEV__ && !config.async) {
184
+ flushSchedulerQueue()
185
+ return
188
186
  }
187
+ nextTick(flushSchedulerQueue)
189
188
  }
190
189
  }
@@ -1,6 +1,4 @@
1
- /* @flow */
2
-
3
- import { _Set as Set, isObject } from '../util/index'
1
+ import { _Set as Set, isObject, isArray } from '../util/index'
4
2
  import type { SimpleSet } from '../util/index'
5
3
  import VNode from '../vdom/vnode'
6
4
 
@@ -11,15 +9,20 @@ const seenObjects = new Set()
11
9
  * getters, so that every nested property inside the object
12
10
  * is collected as a "deep" dependency.
13
11
  */
14
- export function traverse (val: any) {
12
+ export function traverse(val: any) {
15
13
  _traverse(val, seenObjects)
16
14
  seenObjects.clear()
15
+ return val
17
16
  }
18
17
 
19
- function _traverse (val: any, seen: SimpleSet) {
18
+ function _traverse(val: any, seen: SimpleSet) {
20
19
  let i, keys
21
- const isA = Array.isArray(val)
22
- if ((!isA && !isObject(val)) || Object.isFrozen(val) || val instanceof VNode) {
20
+ const isA = isArray(val)
21
+ if (
22
+ (!isA && !isObject(val)) ||
23
+ Object.isFrozen(val) ||
24
+ val instanceof VNode
25
+ ) {
23
26
  return
24
27
  }
25
28
  if (val.__ob__) {