-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
feat: add pause/resume
methods for render
function
#9206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
5a279be
9bda252
c2b7333
df77be4
a5446a3
540e408
a4e43a8
ac2dcd6
b91a0a1
92419a2
34e569c
88a6ac6
1c5b52d
17c975c
b0f1c7c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { ReactiveEffect } from '@vue/reactivity' | ||
|
||
/** | ||
* Extend `ReactiveEffect` by adding `pause` and `resume` methods for controlling the execution of the `render` function. | ||
*/ | ||
export class RenderEffect extends ReactiveEffect { | ||
private _isPaused = false | ||
private _isCalled = false | ||
pause() { | ||
this._isPaused = true | ||
} | ||
resume(runOnce = false) { | ||
if (this._isPaused) { | ||
this._isPaused = false | ||
if (this._isCalled && runOnce) { | ||
super.run() | ||
} | ||
this._isCalled = false | ||
} | ||
} | ||
update() { | ||
if (this._isPaused) { | ||
this._isCalled = true | ||
} else { | ||
return super.run() | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Love the compatibility of pausable effect. Since this is not bound to the runtime/dom, I wonder if this could be generally available in /cc @yyx990803 WDYT? Or do you think it deserves a dedicated RFC? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As the addition of /cc @yyx990803 @antfu |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we could have a prop for KeepAlive to toggle this behavior (and default disabling it to keep existing behaviour)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we can add a prop to preserve the original behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a
lazy
prop to control whether it should pause in the deactivated state.