Skip to content

Commit

Permalink
feat(element): LocalizeMixin
Browse files Browse the repository at this point in the history
  • Loading branch information
alimd committed Dec 28, 2022
1 parent c6912a5 commit 94f0f7f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 53 deletions.
53 changes: 0 additions & 53 deletions ui/element/src/mixins/i18n.ts

This file was deleted.

40 changes: 40 additions & 0 deletions ui/element/src/mixins/localize.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {l10n} from '@alwatr/i18n';
import {LitElement} from 'lit';

import type {Constructor} from '../type.js';

export declare class LocalizeMixinInterface extends LitElement {
protected _signalListenerList: Array<unknown>;
protected l10n: {
localize: typeof l10n.localize;
formatNumber: typeof l10n.formatNumber;
};
}

export function LocalizeMixin<T extends Constructor<LitElement>>(
superClass: T,
): Constructor<LocalizeMixinInterface> & T {
class LocalizeMixinClass extends superClass {
protected _signalListenerList: Array<unknown> = [];

protected l10n = {
localize: l10n.localize,
formatNumber: l10n.formatNumber,
};

override connectedCallback(): void {
super.connectedCallback();
this._signalListenerList.push(
l10n.resourceChangeSignal.addListener(() => {
this._l10nResourceChange();
}),
);
}

protected _l10nResourceChange(): void {
this.requestUpdate();
}
}

return LocalizeMixinClass as unknown as Constructor<LocalizeMixinInterface> & T;
}

0 comments on commit 94f0f7f

Please sign in to comment.