Skip to content

Commit

Permalink
feat: inclusao dos processos de adopted attributeChanged connected di…
Browse files Browse the repository at this point in the history
…dPaint diconnected e on
  • Loading branch information
deMGoncalves committed Jun 28, 2024
1 parent 1a4e979 commit edc9e37
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions packages/standard/on/on.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
const on = new Proxy(
{},
{
get (_, event) {
return (query) => (target, propertyKey) => {
const connectedCallback = target.connectedCallback ?? (() => undefined);
{},
{
get(_, event) {
return (query) => (target, propertyKey) => {
const connectedCallback = target.connectedCallback ?? (() => undefined);

const disconnectedCallback =
target.disconnectedCallback ?? (() => undefined);
const disconnectedCallback =
target.disconnectedCallback ?? (() => undefined);

function listener(this, event) {
event.target.matches(query) && this[propertyKey](event);
}
function listener(event) {
event.target.matches(query) && this[propertyKey](event);
}

Reflect.defineProperty(target, "connectedCallback", {
async value() {
listener.bind(this)
await Reflect.apply(connectedCallback, this, arguments);
await this.shadowRoot.addEventListener(event, listener);
},
writable: true,
});
Reflect.defineProperty(target, "connectedCallback", {
async value() {
listener.bind(this);
await Reflect.apply(connectedCallback, this, arguments);
await this.shadowRoot.addEventListener(event, listener);
},
writable: true,
});

Reflect.defineProperty(target, "disconnectedCallback", {
async value() {
await Reflect.apply(disconnectedCallback, this, arguments);
await this.shadowRoot.removeEventListener(event, listener);
},
writable: true,
});
};
},
},
Reflect.defineProperty(target, "disconnectedCallback", {
async value() {
await Reflect.apply(disconnectedCallback, this, arguments);
await this.shadowRoot.removeEventListener(event, listener);
},
writable: true,
});
};
},
},
);

export default on;

0 comments on commit edc9e37

Please sign in to comment.