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

Decide on proper API Shape #2

Open
bramus opened this issue Aug 30, 2024 · 5 comments
Open

Decide on proper API Shape #2

bramus opened this issue Aug 30, 2024 · 5 comments

Comments

@bramus
Copy link
Owner

bramus commented Aug 30, 2024

Now:

const cssStyleObserver = new CSSStyleObserver(
  observedVariables: string[],
  callback: CSSStyleObserverCallback
);

cssStyleObserver.attach(targetElement: HTMLElement);

But maybe it’s better that this became the following? Then you can have one observer watch multiple elements.

const cssStyleObserver = new CSSStyleObserver(
  callback: CSSStyleObserverCallback
);

cssStyleObserver.attach(
  targetElement: HTMLElement,
  observedVariables: string[]
);

If being able to observer multiple elements is the only goal, though, maybe the following is also OK?

cssStyleObserver.attach(targetElements: NodeList);
@bramus
Copy link
Owner Author

bramus commented Aug 30, 2024

Furthermore, to be in line with MutationObserver, the attach method should be renamed to observe and a bunch of things should move around.

For reference:

const observer = new MutationObserver(callback);
observer.observe(target, options);

@EswaramoorthyKarthikeyan

Can you please emit the updated element

@bramus
Copy link
Owner Author

bramus commented Oct 16, 2024

The element is the one that you are observing.

@EswaramoorthyKarthikeyan
Copy link

EswaramoorthyKarthikeyan commented Oct 16, 2024

I am observing multiple elements, and I want to know which one's style has changed so I can modify that element accordingly.

@bramus
Copy link
Owner Author

bramus commented Oct 16, 2024

I see. Seems like a good addition to go add to the ReturnFormat.OBJECT return format.

Edit: I have split this off into its own issue, as this issue here is more about how to instantiate and attach the CSSStyleObserver

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