import { BalMutationSubject } from "./mutation.subject";
export function ListenToMutation(options) {
    return function (target, _propertyKey, _descriptor) {
        const { connectedCallback, disconnectedCallback } = target;
        target.connectedCallback = function () {
            if (!this._balMutationSubject) {
                this._balMutationSubject = new BalMutationSubject(options);
                this._balMutationSubject.attach(this);
            }
            return connectedCallback && connectedCallback.call(this);
        };
        target.disconnectedCallback = function () {
            if (this._balMutationSubject) {
                this._balMutationSubject.detach();
                this._balMutationSubject = undefined;
            }
            return disconnectedCallback && disconnectedCallback.call(this);
        };
    };
}
