Skip to content

Commit d57a0ec

Browse files
committed
wip
1 parent 00b1f66 commit d57a0ec

File tree

5 files changed

+42
-30
lines changed

5 files changed

+42
-30
lines changed

packages/reactivity/src/effect.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,12 @@ export class ReactiveEffect<T = any> implements ReactiveEffectOptions {
9696
}
9797

9898
resume(): void {
99-
const flags = this.flags
99+
let flags = this.flags
100100
if (flags & EffectFlags.PAUSED) {
101-
this.flags &= ~EffectFlags.PAUSED
101+
this.flags = flags &= ~EffectFlags.PAUSED
102102
}
103103
if (flags & EffectFlags.NOTIFIED) {
104-
this.flags &= ~EffectFlags.NOTIFIED
104+
this.flags = flags &= ~EffectFlags.NOTIFIED
105105
this.notify()
106106
}
107107
}

packages/reactivity/src/ref.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class RefImpl<T = any> implements Dependency {
144144
if (hasChanged(newValue, oldValue)) {
145145
this._rawValue = newValue
146146
this._value =
147-
this._wrap && !useDirectValue ? this._wrap(newValue) : newValue
147+
!useDirectValue && this._wrap ? this._wrap(newValue) : newValue
148148
if (__DEV__) {
149149
triggerEventInfos.push({
150150
target: this,
@@ -154,7 +154,10 @@ class RefImpl<T = any> implements Dependency {
154154
oldValue,
155155
})
156156
}
157-
triggerRef(this as unknown as Ref)
157+
const subs = this.subs
158+
if (subs !== undefined) {
159+
propagate(subs)
160+
}
158161
if (__DEV__) {
159162
triggerEventInfos.pop()
160163
}

packages/runtime-core/src/renderer.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,8 +1599,7 @@ function baseCreateRenderer(
15991599
instance.scope.off()
16001600

16011601
const update = (instance.update = effect.run.bind(effect))
1602-
const job: SchedulerJob = (instance.job = () =>
1603-
effect.dirty && effect.run())
1602+
const job: SchedulerJob = (instance.job = effect.scheduler.bind(effect))
16041603
job.i = instance
16051604
job.id = instance.uid
16061605
effect.scheduler = () => queueJob(job)

packages/runtime-core/src/scheduler.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ function findInsertionIndex(id: number, isPre: boolean) {
9797
* @internal for runtime-vapor only
9898
*/
9999
export function queueJob(job: SchedulerJob, isPre = false): void {
100-
if (!(job.flags! & SchedulerJobFlags.QUEUED)) {
100+
const flags = job.flags!
101+
if (!(flags & SchedulerJobFlags.QUEUED)) {
101102
if (job.id === undefined) {
102103
job.id = isPre ? -1 : Infinity
103104
}
@@ -113,9 +114,7 @@ export function queueJob(job: SchedulerJob, isPre = false): void {
113114
queue.splice(findInsertionIndex(job.id, isPre), 0, job)
114115
}
115116
isPre ? preJobsLength++ : mainJobsLength++
116-
117-
job.flags! |= SchedulerJobFlags.QUEUED
118-
117+
job.flags! = flags | SchedulerJobFlags.QUEUED
119118
queueFlush()
120119
}
121120
}

packages/runtime-vapor/src/renderEffect.ts

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import {
2+
EffectFlags,
23
type EffectScope,
34
ReactiveEffect,
4-
getCurrentScope,
5+
pauseTracking,
6+
resetTracking,
57
} from '@vue/reactivity'
68
import {
79
type SchedulerJob,
@@ -17,24 +19,18 @@ import { invokeArrayFns } from '@vue/shared'
1719

1820
class RenderEffect extends ReactiveEffect {
1921
i: VaporComponentInstance | null
20-
scope: EffectScope | undefined
21-
baseJob: SchedulerJob
22-
postJob: SchedulerJob
22+
job: SchedulerJob
23+
updateJob: SchedulerJob
2324

2425
constructor(public render: () => void) {
2526
super()
2627
const instance = currentInstance as VaporComponentInstance | null
27-
const scope = getCurrentScope()
28-
if (__DEV__ && !__TEST__ && !scope && !isVaporComponent(instance)) {
28+
if (__DEV__ && !__TEST__ && !this.subs && !isVaporComponent(instance)) {
2929
warn('renderEffect called without active EffectScope or Vapor instance.')
3030
}
3131

32-
this.baseJob = () => {
33-
if (this.dirty) {
34-
this.run()
35-
}
36-
}
37-
this.postJob = () => {
32+
const job: SchedulerJob = super.scheduler.bind(this)
33+
this.updateJob = () => {
3834
instance!.isUpdating = false
3935
instance!.u && invokeArrayFns(instance!.u)
4036
}
@@ -48,19 +44,29 @@ class RenderEffect extends ReactiveEffect {
4844
? e => invokeArrayFns(instance.rtg!, e)
4945
: void 0
5046
}
51-
this.baseJob.i = instance
52-
this.baseJob.id = instance.uid
47+
job.i = instance
48+
job.id = instance.uid
5349
}
5450

51+
this.job = job
5552
this.i = instance
56-
this.scope = scope
5753

5854
// TODO recurse handling
5955
}
6056

57+
run(): void {
58+
if (this.deps === undefined) {
59+
super.run()
60+
} else {
61+
pauseTracking()
62+
this.callback()
63+
resetTracking()
64+
}
65+
}
66+
6167
callback(): void {
6268
const instance = this.i!
63-
const scope = this.scope
69+
const scope = this.subs ? (this.subs.sub as EffectScope) : undefined
6470
// renderEffect is always called after user has registered all hooks
6571
const hasUpdateHooks = instance && (instance.bu || instance.u)
6672
if (__DEV__ && instance) {
@@ -73,7 +79,7 @@ class RenderEffect extends ReactiveEffect {
7379
instance.isUpdating = true
7480
instance.bu && invokeArrayFns(instance.bu)
7581
this.render()
76-
queuePostFlushCb(this.postJob)
82+
queuePostFlushCb(this.updateJob)
7783
} else {
7884
this.render()
7985
}
@@ -84,8 +90,13 @@ class RenderEffect extends ReactiveEffect {
8490
}
8591
}
8692

87-
scheduler(): void {
88-
queueJob(this.baseJob)
93+
notify(): void {
94+
const flags = this.flags
95+
if (!(flags & EffectFlags.PAUSED)) {
96+
queueJob(this.job)
97+
} else {
98+
this.flags = flags | EffectFlags.NOTIFIED
99+
}
89100
}
90101
}
91102

0 commit comments

Comments
 (0)