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

When an SVG element is being detached, remove its events #521

Open
wflemingnz-retired opened this issue Apr 5, 2020 · 6 comments
Open

Comments

@wflemingnz-retired
Copy link

In NgxD3timelineComponent, the setter of svgElement attaches events to the SVG when the SVG element itself is attached to the DOM.

We likely should also detach the events in the case where the SVG element is removed or changed. This can be achieved by:

ElementRef<SVGElement> _svgElement;
@ViewChild('svgEl') set svgElement(el: ElementRef<SVGElement>) {
  if(_svgElement){
    this.detachZoom(_svgElement);
  }

  _svgElement = el;
  this.setupZoom(_svgElement);
}
@umarmohammed
Copy link
Member

Could we remove the event handler in onDestroy?

@wflemingnz-retired
Copy link
Author

We could but as I understand it, it wouldn't be as comprehensive as the method I gave.

Consider if view is set(SVG element A), then unset and set again(SVG element B).

Using onDestroy, events will be detached from B but not A.

@umarmohammed
Copy link
Member

umarmohammed commented Apr 5, 2020

I'm not sure that its possible to unset without destroying the component

@wflemingnz-retired
Copy link
Author

If you assign 0,0 to view (or later set view to null), I thought the elements in the ngIf are removed from the DOM - this includes the SVG element.

If inconclusive we could test it.

@umarmohammed
Copy link
Member

Good point. I guess once we start using the view selectors, this should prevent the svg from getting removed.

@wflemingnz-retired
Copy link
Author

I think we might still need the ngIf, as the view has not yet been populated via the ResizeObserver when the app first starts up.

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

No branches or pull requests

2 participants