Skip to content

Commit

Permalink
feat(element): ali
Browse files Browse the repository at this point in the history
  • Loading branch information
alimd committed Feb 6, 2023
1 parent 85f169e commit 25422c4
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion ui/element/src/mixins/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,29 @@ import {createLogger, type AlwatrLogger} from '@alwatr/logger';
import type {LitElement, PropertyValues} from '../lit.js';
import type {Constructor} from '@alwatr/type';

let _lastAli = 0;

export declare class LoggerMixinInterface extends LitElement {
/**
* Alwatr logger index!
*
* Element index for logger ;)
*/
ali: number;

protected _logger: AlwatrLogger;
}

export function LoggerMixin<T extends Constructor<LitElement>>(superClass: T): Constructor<LoggerMixinInterface> & T {
class LoggerMixinClass extends superClass {
protected _logger = createLogger(`<${this.tagName.toLowerCase()}>`);
ali: number;
protected _logger;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
constructor(...args: any[]) {
super(...args);
this.ali = ++_lastAli;
this._logger = createLogger(`<${this.tagName.toLowerCase()}-${this.ali}>`);
this._logger.logMethod('constructor');
}

Expand Down

0 comments on commit 25422c4

Please sign in to comment.