mirror of
https://github.com/yewstack/yew.git
synced 2025-12-08 21:26:25 +00:00
Bring back destroy lifecycle method (#1354)
This reverts commit c9cac6ff952892b17fb121e1aa52301f79a448ad.
This commit is contained in:
parent
429d9674af
commit
0c3c289afe
@ -136,13 +136,8 @@ where
|
|||||||
|
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> Drop for FunctionComponent<T>
|
fn destroy(&mut self) {
|
||||||
where
|
|
||||||
T: FunctionProvider,
|
|
||||||
{
|
|
||||||
fn drop(&mut self) {
|
|
||||||
if let Some(hook_state) = self.hook_state.borrow_mut().deref_mut() {
|
if let Some(hook_state) = self.hook_state.borrow_mut().deref_mut() {
|
||||||
for hook in hook_state.destroy_listeners.drain(..) {
|
for hook in hook_state.destroy_listeners.drain(..) {
|
||||||
hook()
|
hook()
|
||||||
|
|||||||
@ -122,6 +122,9 @@ pub trait Component: Sized + 'static {
|
|||||||
/// }
|
/// }
|
||||||
///# }
|
///# }
|
||||||
fn rendered(&mut self, _first_render: bool) {}
|
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.
|
/// A type which expected as a result of `view` function implementation.
|
||||||
|
|||||||
@ -428,7 +428,7 @@ where
|
|||||||
{
|
{
|
||||||
fn run(self: Box<Self>) {
|
fn run(self: Box<Self>) {
|
||||||
if let Some(mut state) = self.state.borrow_mut().take() {
|
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 {
|
if let Some(last_frame) = &mut state.last_root {
|
||||||
last_frame.detach(&state.parent);
|
last_frame.detach(&state.parent);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user