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

feat: makes Controller.isConnected an observable property #4093

Merged

Conversation

nicholasrice
Copy link
Contributor

@nicholasrice nicholasrice commented Nov 3, 2020

Description

It is currently very difficult to determine when exactly an element is added or removed from the DOM. Custom elements do have connectedCallback and disconnectedCallback but these are really only useful to the class implementation and not external code. There is no connected or disconnected events emitted, and it is using MutationObserver for this case is very difficult / expensive.

whatwg/dom#533 tracks a proposal to patch MutationObserver with connected and disconnected records, but this feature has not made its way into implementation yet.

We can make "connectedness" easy to observe for FASTElement instances though, simply by making the existing Controller.isConnected property observable.

Motivation & context

What does this get us?

  • House-keeping of code relative to, but not implemented in, a FASTElement.
    • adding and removing subscriptions and event listeners, cleaning up element caches, etc.
  • Dependency Injection value reconciliation, where DI container is based on DOM location.

There are some additional uses cases outlined in whatwg/dom#533.

Issue type checklist

  • Chore: A change that does not impact distributed packages.
  • Bug fix: A change that fixes an issue, link to the issue above.
  • New feature: A change that adds functionality.

Is this a breaking change?

  • This change causes current functionality to break.

Adding or modifying component(s) in @microsoft/fast-components checklist

Process & policy checklist

  • I have added tests for my changes.
  • I have tested my changes.
  • I have updated the project documentation to reflect my changes.
  • I have read the CONTRIBUTING documentation and followed the standards for this project.

@nicholasrice nicholasrice self-assigned this Nov 3, 2020
@nicholasrice nicholasrice merged commit 3d49aa2 into master Nov 3, 2020
@nicholasrice nicholasrice deleted the users/nirice/make-Controller.isConnected-observable branch November 3, 2020 23:24
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

Successfully merging this pull request may close these issues.

3 participants