-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
feat: add destroy lifecycle hook to blocks #6678
Conversation
core/block.ts
Outdated
@@ -95,6 +95,9 @@ export class Block implements IASTNodeLocation, IDeletable { | |||
/** An optional method called during initialization. */ | |||
init?: (() => AnyDuringMigration)|null = undefined; | |||
|
|||
/** An optional method called during disposal. */ | |||
destroy?: (() => AnyDuringMigration)|null = undefined; |
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.
Why AnyDuringMigration as the return type rather than void? It also seems like it might be nicer to make it non-optional and just initialize it to null rather than undefined?
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 went with void & removed the |null
. I thought undefined
made more sense as a default value, since this property /is/ optional, and its either defined or its not.
The basics
npm run format
andnpm run lint
The details
Resolves
Fixes #6319 maybe actually finally
Proposed Changes
Adds a new
destroy
lifecycle hook that is called at the end ofdispose
which can be used for cleanup (e.g. of any backing data models for the block).Reason for Changes
Sometimes you need to clean data up!
Test Coverage
Adds tests to make sure dispose gets called at the proper time, and events fired from it are actually fired.
Documentation
N/A
Additional Information
Putting this up as a draft until we're sure we're definitely happy with the design.