-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
useOnBeforeUnload()
on expensive dirty flag
#842
Comments
Would allowing
|
@streamich Yes, that looks good, I've enabled this in my own version. |
@bebbi If you would like to create a PR, would be great! |
feat(useBeforeUnload): allow passing a dirty function (#842)
# [13.25.0](v13.24.1...v13.25.0) (2020-02-15) ### Features * **useBeforeUnload:** allow passing a dirty function ([#842](#842)) ([c4a14a4](c4a14a4))
🎉 This issue has been resolved in version 13.25.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Is your feature request related to a problem? Please describe.
I've considered the
useOnBeforeUnload
hook to warn if a doc has unsaved changes.But it makes no sense because the dirty boolean flag is expensive to calculate (it's a deep comparison between serialized objects).
The way the hook currently works I have to recalculate the dirty flag much more often than necessary.
Describe the solution you'd like
I'd like to propose that
useOnBeforeUnload
hook always registers a handler.dirty
function instead of a booleandirty()
if it's a function, but only at the actual time of unload where it's relevant.That would reduce an expensive calculation to once when it's needed.
For simplicity, I think the approach can be the same for a boolean
dirty
flag since the handler won't take up noticeable resources.Describe alternatives you've considered
I have considered flagging the
isDirty
on any doc change and avoiding re-calculation once it'strue
, but that doesn't make much sense because there's so many changes to the doc variable that are not relevant anymore after it's serialized (such as selection changes).So it looks like I can either PR this for you or build my own hook.
The text was updated successfully, but these errors were encountered: