Bring back destroy lifecycle method (#1354)

This reverts commit c9cac6ff952892b17fb121e1aa52301f79a448ad.
This commit is contained in:
Justin Starry 2020-06-29 22:39:03 +08:00 committed by GitHub
parent 429d9674af
commit 0c3c289afe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 7 deletions

View File

@ -136,13 +136,8 @@ where
ret
}
}
impl<T> Drop for FunctionComponent<T>
where
T: FunctionProvider,
{
fn drop(&mut self) {
fn destroy(&mut self) {
if let Some(hook_state) = self.hook_state.borrow_mut().deref_mut() {
for hook in hook_state.destroy_listeners.drain(..) {
hook()

View File

@ -122,6 +122,9 @@ pub trait Component: Sized + 'static {
/// }
///# }
fn rendered(&mut self, _first_render: bool) {}
/// The `destroy` method is called right before a Component is unmounted.
fn destroy(&mut self) {}
}
/// A type which expected as a result of `view` function implementation.

View File

@ -428,7 +428,7 @@ where
{
fn run(self: Box<Self>) {
if let Some(mut state) = self.state.borrow_mut().take() {
drop(state.component);
state.component.destroy();
if let Some(last_frame) = &mut state.last_root {
last_frame.detach(&state.parent);
}