Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
swarty committed Jan 25, 2024
1 parent b8582f3 commit 60ce07d
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions src/elements.ts
Original file line number Diff line number Diff line change
@@ -664,20 +664,20 @@ export abstract class BaseView<T extends HTMLElement|SVGElement> {
*/
off(events: string, callback?: EventCallback) {
for (const e of words(events)) {
if (!(e in this._events) || callback) unbindEvent(this, e, callback);
if (callback) {
this._events[e] = this._events[e].filter(fn => fn !== callback);
} else {
for (const eventsCallback of this._events[e]) unbindEvent(this, e, eventsCallback);
unbindEvent(this, e, callback);
continue;
}
for (const eventsCallback of this._events[e]) unbindEvent(this, e, eventsCallback);
}
}

/**
* Removes all event listeners from this element
*/
offAll() {
Object.entries(this._events || {}).forEach(([eventName, callbacks]) => {
Object.entries(this._events).forEach(([eventName, callbacks]) => {
callbacks.forEach((callback) => this.off(eventName, callback));
});
}
@@ -710,14 +710,8 @@ export abstract class BaseView<T extends HTMLElement|SVGElement> {
const target = (this._el === document.body ? document : this._el) as HTMLElement;
target.addEventListener(event, eventFunction);

if (event in this._events) {
this._events[event].push(eventFunction);
} else {
Object.assign(
this._events,
{[event]: [eventFunction]}
);
}
if (!(event in this._events)) this._events[event] = [];
this._events[event].push(eventFunction);
}

/**
@@ -737,11 +731,8 @@ export abstract class BaseView<T extends HTMLElement|SVGElement> {
this._mutationObserver.observe(this._el, {attributes: true});
}

if (name in this._mutationObserverCallbacks) {
this._mutationObserverCallbacks[name].push(callback);
} else {
this._mutationObserverCallbacks[name] = [callback];
}
if (!(name in this._mutationObserverCallbacks)) this._mutationObserverCallbacks[name] = [];
this._mutationObserverCallbacks[name].push(callback);

callback(this.attr(name), true);
}

0 comments on commit 60ce07d

Please sign in to comment.