bramus / style-observer

MutationObserver for CSS. Get notified when the computed value of a CSS property changes.
https://brm.us/style-observer
MIT License
304 stars 4 forks source link

Decide on proper API Shape #2

Open bramus opened 3 weeks ago

bramus commented 3 weeks ago

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 commented 3 weeks ago

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);