Skip to content
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

Add support for deferred removal of DOM-elements #1238

Closed
jhsware opened this issue Nov 13, 2017 · 4 comments · Fixed by #1542
Closed

Add support for deferred removal of DOM-elements #1238

jhsware opened this issue Nov 13, 2017 · 4 comments · Fixed by #1542

Comments

@jhsware
Copy link
Contributor

jhsware commented Nov 13, 2017

To perform animations on unmount one currently has to make a clone of the elements belonging to a component. This adds orphan DOM-nodes and requires the animation library to perform cleanup. I have used this technique in https://github.com/jhsware/inferno-animation

It would be great if one on componentWillUnmount could mark the component for deferred removal, perform the animation and then trigger the removal when the animation is done.

componentWillUnmount () {
  this._deferredDOMRemoval = true
  this.doAnimationOnRemove()
}

doAnimationOnRemove () {
  // Perform a beautiful CSS-animation
  this.ref.addEventListener("transitionend", (e) => {
    // Now tell Inferno to remove the DOM-node
    this._removeDOM()
  }, false)
}
@Havunen
Copy link
Member

Havunen commented Nov 14, 2017

There is easier way to accomplish this, Simply do setState before you are removing the element. Then use the state to mark element fe. class "removing" do animation using CSS and then after x amount of time do the actual removal.

But I agree, it would be nice to have library for this, when used with pure JS animations. Maybe somebody could create plugin?

@thysultan
Copy link
Contributor

Related issue #1204

@jhsware
Copy link
Contributor Author

jhsware commented Nov 15, 2017

@Havunen To use the setState approach you need to control the animation from the parent element. But with deferred removal the actual component could do all the work regardless of the parent. This makes for nicer application code because you don't need a wrapper. It would work both for CSS-animations and JS-animations.

@jhsware
Copy link
Contributor Author

jhsware commented Mar 12, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

3 participants