Skip to content

[labs/observers] ResizeController "observe" is available publicly, but "unobserve" is not. #3237

Closed

Description

@Westbrook

Should this be an RFC?

  • This is not a substantial change

Which package is this a feature request for?

Observers (@lit-labs/observers)

Description

You can currently ResizeController.observe(...) new elements across the lifecycle of the controller, but you aren't given API to unobserve those elements. This method should likely be made private so that it is less likely to lead someone to leverage it and some sort of setter for the target (hopefully one that is easier to use than at current and accepts an array of elements) should be surfaced to ensure that more content can be easily managed by the observer.

This seems like a common patterns in the observer controllers, so each might benefit the same API structure.

Happy to mark up a PR for this if it's acceptable.

Alternatives and Workarounds

WORKAROUND:
You can force the type today with:

(this.resizeController as unknown as {
    _observer: ResizeObserver
})._observer.unobserve(item);

ALTERANATIVE 1:
Or the observe method could be made private to clarify that this isn't functionality that should be taken advantage of outside of the host and target arguments in the constructor.

Activity

  1. moved this to 📋 Triaged in Lit Project Boardon Sep 1, 2022
  2. justinfagnani commented on Sep 1, 2022

    @justinfagnani
    Collaborator

    Since ResizeObserver has an unobserve() method, it makes sense for the controller to also, for symmetry. I'd maybe be in favor of removing observe(), but that's a different discussion.

    This is a great issue for a contributino!

  3. moved this from 📋 Triaged to 🤔 In Review in Lit Project Boardon Sep 30, 2022
  4. Repository owner moved this from 🤔 In Review to ✅ Done in Lit Project Boardon Oct 4, 2022
  5. added a commit that references this issue on Oct 4, 2022
    0f787b2
  6. added a commit that references this issue on Nov 30, 2022
    403997b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions