@patternfly/react-charts
Version:
This library provides a set of React chart components for use with the PatternFly reference implementation.
31 lines • 1.11 kB
JavaScript
/**
* Mutation Observer Helper function -- see developer.mozilla.org/en-US/docs/Web/API/MutationObserver/observe
*
* @param {string} selector The DOM selector to watch
* @param {object} opt MutationObserver options
* @param {function} cb Pass Mutation object to a callback function
* @private Not intended as public API and subject to change
*/
export const observe = (selector, opt, cb) => {
let unobserve;
if (selector) {
const Obs = new MutationObserver((m) => [...m].forEach(cb));
document.querySelectorAll(selector).forEach((el) => Obs.observe(el, opt));
unobserve = () => Obs.disconnect();
}
return () => {
if (unobserve) {
unobserve();
}
};
};
// See https://stackoverflow.com/questions/17134823/detect-element-style-changes-with-javascript
export const getMutationObserver = (nodeSelector, cb) => observe(nodeSelector, {
attributesList: ['style'], // Only the "style" attribute
attributeOldValue: true // Report also the oldValue
}, (m) => {
if (cb) {
cb(m);
}
});
//# sourceMappingURL=observe.js.map