refactor(wepy): $dirty 调用时机由 Observer 改到 Watcher,解耦 RenderWatcher 和 O… #2801
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Observer 之所以会引用 vm,是为了响应数据被修改时,把修改信息放入 vm.$dirty。
其实可以换个思路。把修改信息通过 notify 往上传给Watcher,由Watcher调用 vm.$dirty。
除了解决 GC 之外,还解决了另一个问题,响应数据和关联的第一个 vm 耦合。
举个例子,有一个 obj。
pageA.data.a = obj。pageB.data.b = obj。
obj.x = 123,只有页面 A 会更新,而页面 B 无法更新,因为 obj 引用的 vm 是 PagaA
Checklist
npm run test
passes