Skip to content

Commit

Permalink
fix(element): compatible with new signal api
Browse files Browse the repository at this point in the history
  • Loading branch information
alimd committed Jan 29, 2023
1 parent 3ec615a commit 020a083
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions ui/element/src/mixins/signal.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import {unsubscribe} from '@alwatr/signal/core2.js';

import type {ListenerSpec} from '@alwatr/signal/type.js';
import type {Constructor} from '@alwatr/type';
import type {LitElement} from 'lit';

export declare class SignalMixinInterface extends LitElement {
protected _signalListenerList: Array<unknown>;
protected _signalListenerList: Array<ListenerSpec>;
}

export function SignalMixin<T extends Constructor<LitElement>>(superClass: T): Constructor<SignalMixinInterface> & T {
class SignalMixinClass extends superClass {
protected _signalListenerList: Array<Record<string, unknown>> = [];
protected _signalListenerList: Array<ListenerSpec> = [];

override disconnectedCallback(): void {
super.disconnectedCallback();

for (const listener of this._signalListenerList) {
if (typeof listener.remove === 'function') {
listener.remove();
}
unsubscribe(listener);
}
this._signalListenerList.length = 0;
this._signalListenerList = [];
super.disconnectedCallback();
}
}

Expand Down

0 comments on commit 020a083

Please sign in to comment.