@studiometa/js-toolkit
Version:
A set of useful little bits of JavaScript to boost your project! 🚀
35 lines (34 loc) • 896 B
JavaScript
import { AbstractService } from "./AbstractService.js";
import { isEmpty } from "../utils/is.js";
class MutationService extends AbstractService {
props = {
mutations: []
};
target;
options;
observer;
constructor(target, options) {
super();
this.target = target ?? document.documentElement;
this.options = options;
}
init() {
this.observer = new MutationObserver((mutations) => {
this.props.mutations = mutations;
this.trigger(this.props);
});
this.observer.observe(this.target, isEmpty(this.options) ? { attributes: true } : this.options);
}
kill() {
this.observer.disconnect();
this.observer = null;
}
}
function useMutation(target, options) {
return MutationService.getInstance([target, JSON.stringify(options)], target, options);
}
export {
MutationService,
useMutation
};
//# sourceMappingURL=MutationService.js.map