[RFC] Add pause/resume function to ReactiveEffect
#599
Alfred-Skyblue
started this conversation in
RFC Discussions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Start Date: 2023-11-14
Target Major Version: 3.x
Implementation PR: vuejs/core#9651
Summary
The proposal recommends adding
pause/resumemethods toRenderEffectfor controlling the pause and resume of effects.pausemethod is used to pause the execution of aReactiveEffect.resumemethod is used to resume the execution of aReactiveEffect.EffectScopehas been extended withpauseandresumemethods, which can be used to pause/resume the execution of allReactiveEffectswithin theEffectScope.Add theUsers have the autonomy to control the invocation of pause/resume actions during the keep-alive lifecycle.lazyattribute tokeep-aliveso that, during theactivatedanddeactivatedphases, you can control the pause and resume of theEffectScopefor the component instance.Motivation
When the
keep-aliveis in adeactivatedstate, if theeffectwithin the component depends on an external reactive variable, unnecessary updates occur when this variable is updated. In this RFC, we address this issue by pausing theeffectto prevent these unnecessary updates.relate: vuejs/core#5386
Basic example
Detailed design
pausemethod is used to pause the execution of aReactiveEffect. If an effect is triggered during the pause process, the effect will be placed into thepausedQueueEffects.resumemethod is used to resume the execution of aReactiveEffect. This method takes abooleanparameter. If theresumemethod is called withtrue, and the currenteffectexists inpausedQueueEffects, immediately trigger theeffectonce.Unresolved questions
watchsimilar to that of a counter, it may result in counting errors.Welcome to discuss.
Beta Was this translation helpful? Give feedback.
All reactions