@mpxjs/core 2.10.18-beta.2 → 2.10.18-beta.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/core",
3
- "version": "2.10.18-beta.2",
3
+ "version": "2.10.18-beta.3",
4
4
  "description": "mpx runtime core",
5
5
  "keywords": [
6
6
  "miniprogram",
package/src/core/proxy.js CHANGED
@@ -166,7 +166,6 @@ export default class MpxProxy {
166
166
  }
167
167
 
168
168
  created () {
169
- console.log('[mpx] create proxy instance')
170
169
  if (__mpx_dynamic_runtime__) {
171
170
  // 缓存上下文,在 destoryed 阶段删除
172
171
  contextMap.set(this.uid, this.target)
@@ -753,13 +752,6 @@ export default class MpxProxy {
753
752
  const moduleId = this.target.__moduleId
754
753
  const dynamicTarget = this.target.__dynamic
755
754
 
756
- const debugConfig = typeof global.__getMpxRenderEffectDebugRules === 'function'
757
- ? global.__getMpxRenderEffectDebugRules(this.options?.mpxFileResource)
758
- : {
759
- debug: 1,
760
- name: `MpxRenderEffect-${this.options?.mpxFileResource || 'unknown'}`
761
- }
762
-
763
755
  const effect = this.effect = new ReactiveEffect(() => {
764
756
  // pre render for props update
765
757
  if (this.propsUpdatedFlag) {
@@ -789,9 +781,8 @@ export default class MpxProxy {
789
781
  } else {
790
782
  this.render()
791
783
  }
792
- }, () => queueJob(update), this.scope, this.scope, debugConfig.debug, debugConfig.name)
784
+ }, () => queueJob(update), this.scope)
793
785
 
794
- console.log(`[mpx] ${this.options?.mpxFileResource} will initRender`)
795
786
  const update = this.update = effect.run.bind(effect)
796
787
  update.id = this.uid
797
788
  // render effect允许自触发
@@ -32,7 +32,7 @@ export const arrayMethods = Object.create(arrayProto)
32
32
  }
33
33
  if (inserted) ob.observeArray(inserted)
34
34
  // notify change
35
- ob.dep.notify(method, '[Array Method]', '[Array Method]', new Error('此时被通知变更').stack)
35
+ ob.dep.notify()
36
36
  }
37
37
  return result
38
38
  })
@@ -3,7 +3,7 @@ import Dep from './dep'
3
3
  import { createRef } from './ref'
4
4
  import { ReactiveEffect } from './effect'
5
5
 
6
- export function computed (getterOrOptions, options = {}) {
6
+ export function computed (getterOrOptions) {
7
7
  let getter, setter
8
8
  if (isFunction(getterOrOptions)) {
9
9
  getter = getterOrOptions
@@ -17,7 +17,7 @@ export function computed (getterOrOptions, options = {}) {
17
17
  let value
18
18
  const effect = new ReactiveEffect(getter, () => {
19
19
  dirty = true
20
- }, undefined, options.debug || 0, options.name || 'anonymous computed')
20
+ })
21
21
 
22
22
  return createRef({
23
23
  get: () => {
@@ -7,50 +7,30 @@ let uid = 0
7
7
  * directives subscribing to it.
8
8
  */
9
9
  export default class Dep {
10
- constructor (key) {
10
+ constructor () {
11
11
  this.id = uid++
12
12
  this.subs = []
13
- this.addSubStacks = new Map()
14
- this.key = key
15
13
  }
16
14
 
17
15
  addSub (sub) {
18
- const addSubStack = new Error('此时被添加到订阅者列表').stack
19
- this.addSubStacks.set(sub, addSubStack)
20
16
  this.subs.push(sub)
21
17
  }
22
18
 
23
19
  removeSub (sub) {
24
20
  remove(this.subs, sub)
25
- this.addSubStacks.delete(sub)
26
21
  }
27
22
 
28
- depend (key, value) {
23
+ depend () {
29
24
  if (Dep.target) {
30
- // if (this.key === 'link_params' || key === 'link_params') console.log(new Error('此时被依赖').stack)
31
- Dep.target.addDep(this, key, value)
25
+ Dep.target.addDep(this)
32
26
  }
33
27
  }
34
28
 
35
- notify (key, value, oldvalue, stack) {
29
+ notify () {
36
30
  // stabilize the subscriber list first
37
31
  const subs = this.subs.slice()
38
- try {
39
- console.log('[Mpx Dep] notify ' +
40
- this.subs.length +
41
- ' subs, from ' +
42
- key +
43
- ': ' +
44
- (typeof oldvalue === 'object' ? JSON.stringify(oldvalue) : oldvalue) +
45
- ' -> ' +
46
- (typeof value === 'object' ? JSON.stringify(value) : value) +
47
- ', subs: ' +
48
- subs.map(s => `id:${s.id} name:${s.name}`).join(', '))
49
- } catch (e) {
50
- // do nothing
51
- }
52
32
  for (let i = 0, l = subs.length; i < l; i++) {
53
- subs[i].update(key, value, oldvalue, stack, this.addSubStacks.get(subs[i]))
33
+ subs[i].update()
54
34
  }
55
35
  }
56
36
  }
@@ -17,8 +17,6 @@ export function resetTracking () {
17
17
  shouldTrack = last === undefined ? true : last
18
18
  }
19
19
 
20
- global.__setMpxReactiveEffect = (value) => {}
21
-
22
20
  export class ReactiveEffect {
23
21
  active = true
24
22
  deps = []
@@ -26,45 +24,15 @@ export class ReactiveEffect {
26
24
  depIds = new Set()
27
25
  newDepIds = new Set()
28
26
  allowRecurse = false
29
- debug = 0
30
- name = 'no-name'
31
27
 
32
28
  constructor (
33
29
  fn,
34
30
  scheduler,
35
- scope,
36
- debug,
37
- name
31
+ scope
38
32
  ) {
39
- this.debug = debug || 0
40
- this.name = name || 'no-name'
41
33
  this.id = ++uid
42
- this.fn = (...args) => {
43
- this.debug > 0 && console.log(`[Mpx Effect] id:${this.id} name: ${this.name} will run`)
44
- this.debug > 1 && console.log(new Error('此时触发了run').stack)
45
- const t = global.__setMpxReactiveEffect
46
- global.__setMpxReactiveEffect = (option) => {
47
- Object.entries(option).forEach(([key, value]) => {
48
- this[key] = value
49
- })
50
- }
51
- const result = fn(...args)
52
- global.__setMpxReactiveEffect = t
53
- return result
54
- }
55
- this.scheduler = (...args) => {
56
- this.debug > 0 && console.log(`[Mpx Effect] id:${this.id} name: ${this.name} will scheduled`)
57
- this.debug > 1 && console.log(new Error('此时触发scheduler').stack)
58
- const t = global.__setMpxReactiveEffect
59
- global.__setMpxReactiveEffect = (option) => {
60
- Object.entries(option).forEach(([key, value]) => {
61
- this[key] = value
62
- })
63
- }
64
- const result = scheduler(...args)
65
- global.__setMpxReactiveEffect = t
66
- return result
67
- }
34
+ this.fn = fn
35
+ this.scheduler = scheduler
68
36
  this.pausedState = PausedState.resumed
69
37
  recordEffectScope(this, scope)
70
38
  }
@@ -85,14 +53,14 @@ export class ReactiveEffect {
85
53
  }
86
54
 
87
55
  // add dependency to this
88
- addDep (dep, key, value) {
56
+ addDep (dep) {
89
57
  if (!shouldTrack) return
90
58
  const id = dep.id
91
59
  if (!this.newDepIds.has(id)) {
92
60
  this.newDepIds.add(id)
93
61
  this.newDeps.push(dep)
94
62
  if (!this.depIds.has(id)) {
95
- dep.addSub(this, key, value)
63
+ dep.addSub(this)
96
64
  }
97
65
  }
98
66
  }
@@ -117,20 +85,12 @@ export class ReactiveEffect {
117
85
  }
118
86
 
119
87
  // same as trigger
120
- update (key, value, oldvalue, stack, fromAddSubStack) {
121
- const debugOptions = global.__getMpxReactiveEffectDebugRules?.(key, value)
122
- const debug = debugOptions ? debugOptions.debug : this.debug
88
+ update () {
123
89
  // avoid dead cycle
124
90
  if (Dep.target !== this || this.allowRecurse) {
125
91
  if (this.pausedState !== PausedState.resumed) {
126
- debug > 0 && console.log(`[Mpx Effect] id:${this.id} name: ${this.name} pausedState will set to dirty with, from ${key}: ${typeof value === 'object' ? JSON.stringify(value) : value}`)
127
- debug > 1 && console.log(stack)
128
- debug > 2 && console.log(fromAddSubStack)
129
92
  this.pausedState = PausedState.dirty
130
93
  } else {
131
- debug > 0 && console.log(`[Mpx Effect] id:${this.id} name: ${this.name} will updated, from ${key}: ${typeof value === 'object' ? JSON.stringify(value) : value}`)
132
- debug > 1 && console.log(stack)
133
- debug > 2 && console.log(fromAddSubStack)
134
94
  this.scheduler ? this.scheduler() : this.run()
135
95
  }
136
96
  }
@@ -110,7 +110,7 @@ function observe (value, shallow) {
110
110
  * Define a reactive property on an Object.
111
111
  */
112
112
  export function defineReactive (obj, key, val, shallow) {
113
- const dep = new Dep(key)
113
+ const dep = new Dep()
114
114
 
115
115
  const property = Object.getOwnPropertyDescriptor(obj, key)
116
116
  if (property && property.configurable === false) {
@@ -121,8 +121,6 @@ export function defineReactive (obj, key, val, shallow) {
121
121
  const getter = property && property.get
122
122
  const setter = property && property.set
123
123
 
124
- const stack = new Error().stack
125
-
126
124
  let childOb = shallow ? getObserver(val) : observe(val)
127
125
  Object.defineProperty(obj, key, {
128
126
  enumerable: true,
@@ -130,9 +128,9 @@ export function defineReactive (obj, key, val, shallow) {
130
128
  get: function reactiveGetter () {
131
129
  const value = getter ? getter.call(obj) : val
132
130
  if (Dep.target) {
133
- dep.depend(key, value)
131
+ dep.depend()
134
132
  if (childOb) {
135
- childOb.dep.depend(key, value)
133
+ childOb.dep.depend()
136
134
  if (Array.isArray(value)) {
137
135
  dependArray(value)
138
136
  }
@@ -142,12 +140,10 @@ export function defineReactive (obj, key, val, shallow) {
142
140
  },
143
141
  set: function reactiveSetter (newVal) {
144
142
  const value = getter ? getter.call(obj) : val
145
- let oldVal = value
146
143
  if (!(shallow && isForceTrigger) && !hasChanged(newVal, value)) {
147
144
  return
148
145
  }
149
146
  if (!shallow && isRef(value) && !isRef(newVal)) {
150
- oldVal = value.value
151
147
  value.value = newVal
152
148
  } else if (setter) {
153
149
  setter.call(obj, newVal)
@@ -155,7 +151,7 @@ export function defineReactive (obj, key, val, shallow) {
155
151
  val = newVal
156
152
  }
157
153
  childOb = shallow ? getObserver(newVal) : observe(newVal)
158
- dep.notify(key, newVal, oldVal, stack)
154
+ dep.notify()
159
155
  }
160
156
  })
161
157
  }
@@ -180,9 +176,8 @@ export function set (target, key, val) {
180
176
  target[key] = val
181
177
  return val
182
178
  }
183
- const oldVal = target[key]
184
179
  defineReactive(ob.value, key, val, ob.shallow)
185
- ob.dep.notify(key, val, oldVal, new Error('此时被通知变更').stack)
180
+ ob.dep.notify()
186
181
  return val
187
182
  }
188
183
 
@@ -198,12 +193,11 @@ export function del (target, key) {
198
193
  if (!hasOwn(target, key)) {
199
194
  return
200
195
  }
201
- const oldVal = target[key]
202
196
  delete target[key]
203
197
  if (!ob) {
204
198
  return
205
199
  }
206
- ob.dep.notify(key, undefined, oldVal, new Error('此时被通知变更').stack)
200
+ ob.dep.notify()
207
201
  }
208
202
 
209
203
  /**
@@ -214,7 +208,7 @@ function dependArray (arr) {
214
208
  for (let i = 0, l = arr.length; i < l; i++) {
215
209
  const item = arr[i]
216
210
  const ob = getObserver(item)
217
- ob && ob.dep.depend(i, item)
211
+ ob && ob.dep.depend()
218
212
  if (Array.isArray(item)) {
219
213
  dependArray(item)
220
214
  }
@@ -137,7 +137,7 @@ export function watch (source, cb, options = {}) {
137
137
 
138
138
  job.allowRecurse = !!cb
139
139
 
140
- const effect = new ReactiveEffect(getter, scheduler, undefined, options.debug || 0, options.name || 'anonymous watch')
140
+ const effect = new ReactiveEffect(getter, scheduler)
141
141
 
142
142
  if (cb) {
143
143
  if (immediate) {
@@ -33,13 +33,12 @@ function getSystemInfo () {
33
33
  }
34
34
  }
35
35
 
36
- function createEffect (proxy, componentsMap, rawOptions) {
36
+ function createEffect (proxy, componentsMap) {
37
37
  const update = proxy.update = () => {
38
38
  // react update props in child render(async), do not need exec pre render
39
39
  // if (proxy.propsUpdatedFlag) {
40
40
  // proxy.updatePreRender()
41
41
  // }
42
- // console.log(`[mpx] ${proxy.options?.mpxFileResource} 组件render响应时数据变更,开始修改stateVersion,驱动组件更新`)
43
42
  if (proxy.isMounted()) {
44
43
  proxy.callHook(BEFOREUPDATE)
45
44
  proxy.pendingUpdatedFlag = true
@@ -62,18 +61,11 @@ function createEffect (proxy, componentsMap, rawOptions) {
62
61
  return createElement(type, ...rest)
63
62
  }
64
63
 
65
- const debugConfig = typeof global.__getMpxRenderEffectDebugRules === 'function'
66
- ? global.__getMpxRenderEffectDebugRules(rawOptions.mpxFileResource)
67
- : {
68
- debug: 1,
69
- name: `MpxRenderEffect-${rawOptions.mpxFileResource || 'unknown'}`
70
- }
71
-
72
64
  proxy.effect = new ReactiveEffect(() => {
73
65
  // reset instance
74
66
  proxy.target.__resetInstance()
75
67
  return callWithErrorHandling(proxy.target.__injectedRender.bind(proxy.target), proxy, 'render function', [innerCreateElement, getComponent])
76
- }, () => { return queueJob(update) }, proxy.scope, debugConfig.debug, debugConfig.name)
68
+ }, () => queueJob(update), proxy.scope)
77
69
  // render effect允许自触发
78
70
  proxy.toggleRecurse(true)
79
71
  }
@@ -340,7 +332,7 @@ function createInstance ({ propsRef, type, rawOptions, currentInject, validProps
340
332
  stateVersion: Symbol(),
341
333
  subscribe: (onStoreChange) => {
342
334
  if (!proxy.effect) {
343
- createEffect(proxy, componentsMap, rawOptions)
335
+ createEffect(proxy, componentsMap)
344
336
  proxy.stateVersion = Symbol()
345
337
  }
346
338
  proxy.onStoreChange = onStoreChange
@@ -356,7 +348,7 @@ function createInstance ({ propsRef, type, rawOptions, currentInject, validProps
356
348
  })
357
349
  // react数据响应组件更新管理器
358
350
  if (!proxy.effect) {
359
- createEffect(proxy, componentsMap, rawOptions)
351
+ createEffect(proxy, componentsMap)
360
352
  }
361
353
 
362
354
  return instance
@@ -733,15 +725,6 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
733
725
  proxy.memoVersion = Symbol()
734
726
  }
735
727
 
736
- // if (rawOptions.mpxFileResource.includes('nav.mpx')) {
737
- // const stateVersionChange = proxy.stateVersion === global.__mpxNavStateVersion
738
- // const memoVersionChange = proxy.memoVersion === global.__mpxNavMemoVersion
739
- // const propsChange = props === global.__mpxNavProps
740
- // console.log(`[mpx] nav.mpx render, stateVersionChange: ${stateVersionChange}, memoVersionChange: ${memoVersionChange}, propsChange: ${propsChange}`)
741
- // global.__mpxNavStateVersion = proxy.stateVersion
742
- // global.__mpxNavMemoVersion = proxy.memoVersion
743
- // global.__mpxNavProps = props
744
- // }
745
728
  const finalMemoVersion = useMemo(() => {
746
729
  if (!hasPendingJob(proxy.update)) {
747
730
  proxy.finalMemoVersion = Symbol()