Skip to content

Commit

Permalink
Bring back destroy lifecycle method (yewstack#1354)
Browse files Browse the repository at this point in the history
This reverts commit c9cac6f.
  • Loading branch information
jstarry committed Jun 29, 2020
1 parent 429d967 commit 0c3c289
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
7 changes: 1 addition & 6 deletions yew-functional/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions yew/src/html/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion yew/src/html/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 0c3c289

Please sign in to comment.