@patternfly/react-charts
Version:
This library provides a set of React chart components for use with the PatternFly reference implementation.
36 lines • 1.32 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getMutationObserver = exports.observe = void 0;
/**
* 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
*/
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();
}
};
};
exports.observe = observe;
// See https://stackoverflow.com/questions/17134823/detect-element-style-changes-with-javascript
const getMutationObserver = (nodeSelector, cb) => (0, exports.observe)(nodeSelector, {
attributesList: ['style'], // Only the "style" attribute
attributeOldValue: true // Report also the oldValue
}, (m) => {
if (cb) {
cb(m);
}
});
exports.getMutationObserver = getMutationObserver;
//# sourceMappingURL=observe.js.map