11import {
2+ EffectFlags ,
23 type EffectScope ,
34 ReactiveEffect ,
4- getCurrentScope ,
5+ pauseTracking ,
6+ resetTracking ,
57} from '@vue/reactivity'
68import {
79 type SchedulerJob ,
@@ -17,24 +19,18 @@ import { invokeArrayFns } from '@vue/shared'
1719
1820class 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