@mpxjs/core 2.7.52 → 2.8.0-beta.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 (62) hide show
  1. package/@types/index.d.ts +342 -27
  2. package/package.json +10 -5
  3. package/src/convertor/convertor.js +2 -2
  4. package/src/convertor/mergeLifecycle.js +4 -4
  5. package/src/convertor/wxToAli.js +3 -4
  6. package/src/convertor/wxToSwan.js +2 -2
  7. package/src/convertor/wxToTt.js +1 -10
  8. package/src/convertor/wxToWeb.js +14 -7
  9. package/src/core/implement.js +2 -2
  10. package/src/core/injectMixins.js +1 -1
  11. package/src/core/innerLifecycle.js +15 -2
  12. package/src/core/mergeOptions.js +11 -5
  13. package/src/core/proxy.js +343 -229
  14. package/src/core/transferOptions.js +5 -2
  15. package/src/helper/const.js +10 -0
  16. package/src/index.js +73 -147
  17. package/src/observer/array.js +12 -17
  18. package/src/observer/computed.js +27 -56
  19. package/src/observer/dep.js +1 -1
  20. package/src/observer/effect.js +113 -0
  21. package/src/observer/effectScope.js +109 -0
  22. package/src/observer/{index.js → reactive.js} +74 -70
  23. package/src/observer/ref.js +97 -0
  24. package/src/observer/scheduler.js +171 -56
  25. package/src/observer/watch.js +163 -39
  26. package/src/platform/builtInMixins/i18nMixin.js +238 -31
  27. package/src/platform/builtInMixins/pageScrollMixin.web.js +4 -5
  28. package/src/platform/builtInMixins/pageStatusMixin.js +76 -54
  29. package/src/platform/builtInMixins/pageStatusMixin.web.js +35 -22
  30. package/src/platform/builtInMixins/proxyEventMixin.js +40 -22
  31. package/src/platform/builtInMixins/proxyEventMixin.web.js +16 -24
  32. package/src/platform/builtInMixins/refsMixin.js +82 -73
  33. package/src/platform/builtInMixins/refsMixin.web.js +0 -47
  34. package/src/platform/builtInMixins/relationsMixin.js +10 -9
  35. package/src/platform/builtInMixins/renderHelperMixin.js +1 -1
  36. package/src/platform/builtInMixins/showMixin.js +1 -1
  37. package/src/platform/createApp.js +5 -5
  38. package/src/platform/export/api.js +23 -0
  39. package/src/platform/export/api.web.js +26 -0
  40. package/src/platform/export/index.js +45 -0
  41. package/src/platform/export/index.web.js +36 -0
  42. package/src/platform/index.js +1 -5
  43. package/src/platform/patch/ali/getDefaultOptions.js +33 -31
  44. package/src/platform/patch/ali/lifecycle.js +21 -13
  45. package/src/platform/patch/builtInKeysMap.js +2 -1
  46. package/src/platform/patch/index.js +4 -9
  47. package/src/platform/patch/swan/getDefaultOptions.js +3 -3
  48. package/src/platform/patch/swan/lifecycle.js +17 -14
  49. package/src/platform/patch/web/getDefaultOptions.js +40 -16
  50. package/src/platform/patch/web/lifecycle.js +6 -3
  51. package/src/platform/patch/wx/getDefaultOptions.js +38 -31
  52. package/src/platform/patch/wx/lifecycle.js +18 -11
  53. package/src/runtime/createFactory.js +6 -2
  54. package/src/vue.web.js +3 -0
  55. package/src/vuePlugin.js +31 -0
  56. package/src/core/createStore.js +0 -241
  57. package/src/core/mapStore.js +0 -94
  58. package/src/helper/env.js +0 -20
  59. package/src/helper/getByPath.js +0 -127
  60. package/src/helper/log.js +0 -31
  61. package/src/helper/utils.js +0 -652
  62. package/src/observer/watcher.js +0 -244
@@ -1,244 +0,0 @@
1
- import { queueWatcher, dequeueWatcher } from './scheduler'
2
- import { pushTarget, popTarget } from './dep'
3
- import { getByPath, isObject, remove } from '../helper/utils'
4
-
5
- let uid = 0
6
-
7
- /**
8
- * A watcher parses an expression, collects dependencies,
9
- * and fires callback when the expression value changes.
10
- * This is used for both the $watch() api and directives.
11
- */
12
- export default class Watcher {
13
- constructor (
14
- vm,
15
- expOrFn,
16
- cb,
17
- options
18
- ) {
19
- this.vm = vm
20
- vm._watchers = vm._watchers || []
21
- vm._watchers.push(this)
22
- // options
23
- if (options) {
24
- this.deep = !!options.deep
25
- this.lazy = !!options.lazy
26
- this.sync = !!options.sync
27
- this.name = options.name
28
- } else {
29
- this.deep = this.lazy = this.sync = false
30
- }
31
- this.cb = cb
32
- this.id = ++uid // uid for batching
33
- this.active = true
34
- this.immediateAsync = false
35
- // 是否暂停,默认为否
36
- this.paused = false
37
- // 是否可被暂停,默认为否,不可被暂停
38
- this.pausable = !!(options && options.pausable) || false
39
- this.dirty = this.lazy // for lazy watchers
40
- this.deps = []
41
- this.newDeps = []
42
- this.depIds = new Set()
43
- this.newDepIds = new Set()
44
- this.expression = process.env.NODE_ENV !== 'production' ? expOrFn.toString() : ''
45
- // parse expression for getter
46
- if (typeof expOrFn === 'function') {
47
- this.getter = expOrFn
48
- } else {
49
- this.getter = function () {
50
- return getByPath(this, expOrFn)
51
- }
52
- }
53
- this.value = this.lazy
54
- ? undefined
55
- : this.get()
56
- }
57
-
58
- /**
59
- * Evaluate the getter, and re-collect dependencies.
60
- */
61
- get () {
62
- pushTarget(this)
63
- let value
64
- const vm = this.vm
65
- try {
66
- value = this.getter.call(vm.target)
67
- } catch (e) {
68
- throw e
69
- } finally {
70
- // "touch" every property so they are all tracked as
71
- // dependencies for deep watching
72
- if (this.deep) {
73
- traverse(value)
74
- }
75
- popTarget()
76
- this.cleanupDeps()
77
- }
78
- return value
79
- }
80
-
81
- /**
82
- * Add a dependency to this directive.
83
- */
84
- addDep (dep) {
85
- const id = dep.id
86
- if (!this.newDepIds.has(id)) {
87
- this.newDepIds.add(id)
88
- this.newDeps.push(dep)
89
- if (!this.depIds.has(id)) {
90
- dep.addSub(this)
91
- }
92
- }
93
- }
94
-
95
- /**
96
- * Clean up for dependency collection.
97
- */
98
- cleanupDeps () {
99
- let i = this.deps.length
100
- while (i--) {
101
- const dep = this.deps[i]
102
- if (!this.newDepIds.has(dep.id)) {
103
- dep.removeSub(this)
104
- }
105
- }
106
- let tmp = this.depIds
107
- this.depIds = this.newDepIds
108
- this.newDepIds = tmp
109
- this.newDepIds.clear()
110
- tmp = this.deps
111
- this.deps = this.newDeps
112
- this.newDeps = tmp
113
- this.newDeps.length = 0
114
- }
115
-
116
- /**
117
- * Subscriber interface.
118
- * Will be called when a dependency changes.
119
- */
120
- // 支持临时将某个异步watcher修改为sync执行,在模拟setData时使用
121
- update (sync) {
122
- /* istanbul ignore else */
123
- if (this.lazy || this.paused) {
124
- this.dirty = true
125
- } else if (this.sync || sync) {
126
- if (sync) dequeueWatcher(this)
127
- this.run()
128
- } else {
129
- queueWatcher(this)
130
- }
131
- }
132
-
133
- pause () {
134
- // pausable=false 不可暂停
135
- if (!this.pausable) return
136
- this.paused = true
137
- }
138
- resume () {
139
- // pausable=false 不可恢复
140
- if (!this.pausable) return
141
- // paused 阶段被触发,则 resume 后执行一次run
142
- this.paused = false
143
- if (this.dirty) {
144
- this.dirty = false
145
- this.run()
146
- }
147
- }
148
- /**
149
- * Scheduler job interface.
150
- * Will be called by the scheduler.
151
- */
152
- run () {
153
- if (this.active) {
154
- const value = this.get()
155
- if (this.immediateAsync) {
156
- this.immediateAsync = false
157
- this.value = value
158
- this.cb.call(this.vm.target, value)
159
- } else if (
160
- value !== this.value ||
161
- // Deep watchers and watchers on Object/Arrays should fire even
162
- // when the value is the same, because the value may
163
- // have mutated.
164
- isObject(value) ||
165
- this.deep
166
- ) {
167
- // set new value
168
- const oldValue = this.value
169
- this.value = value
170
- this.cb.call(this.vm.target, value, oldValue)
171
- }
172
- }
173
- }
174
-
175
- /**
176
- * Evaluate the value of the watcher.
177
- * This only gets called for lazy watchers.
178
- */
179
- evaluate () {
180
- this.value = this.get()
181
- this.dirty = false
182
- }
183
-
184
- /**
185
- * Depend on all deps collected by this watcher.
186
- */
187
- depend () {
188
- let i = this.deps.length
189
- while (i--) {
190
- this.deps[i].depend()
191
- }
192
- }
193
-
194
- /**
195
- * Remove self from all dependencies' subscriber list.
196
- */
197
- teardown () {
198
- if (this.active) {
199
- if (this.vm.state !== '__destroyed__') {
200
- remove(this.vm._watchers, this)
201
- }
202
- let i = this.deps.length
203
- while (i--) {
204
- this.deps[i].removeSub(this)
205
- }
206
- this.active = false
207
- }
208
- }
209
- }
210
-
211
- /**
212
- * Recursively traverse an object to evoke all converted
213
- * getters, so that every nested property inside the object
214
- * is collected as a "deep" dependency.
215
- */
216
- const seenObjects = new Set()
217
-
218
- function traverse (val) {
219
- seenObjects.clear()
220
- _traverse(val, seenObjects)
221
- }
222
-
223
- function _traverse (val, seen) {
224
- let i, keys
225
- const isA = Array.isArray(val)
226
- if ((!isA && !isObject(val)) || !Object.isExtensible(val)) {
227
- return
228
- }
229
- if (val.__ob__) {
230
- const depId = val.__ob__.dep.id
231
- if (seen.has(depId)) {
232
- return
233
- }
234
- seen.add(depId)
235
- }
236
- if (isA) {
237
- i = val.length
238
- while (i--) _traverse(val[i], seen)
239
- } else {
240
- keys = Object.keys(val)
241
- i = keys.length
242
- while (i--) _traverse(val[keys[i]], seen)
243
- }
244
- }