Skip to content

Commit 442efb5

Browse files
committed
perf: avoid polluting Object.assign(this)
1 parent 71157fe commit 442efb5

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

lib/src/highlight-js.directive.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,21 @@ declare const ngDevMode: boolean;
1515
exportAs: 'highlightJs',
1616
})
1717
export class HighlightJsDirective implements AfterViewInit, OnDestroy {
18-
readonly options = input<Partial<HLJSOptions>>();
19-
readonly l = input<string>('html', { alias: 'lang'});
18+
private cog = inject(HIGHLIGHTJS_CONFIG, { optional: true });
19+
readonly options = input<Partial<HLJSOptions>>(this.cog?.options ?? {});
20+
readonly lang = input<string>(this.cog?.lang ?? 'html');
2021
readonly code = model<string>();
21-
readonly mode = input<'default' | 'simple'>('simple');
22+
readonly mode = input<'default' | 'simple'>(this.cog?.mode ?? 'simple');
2223

2324
protected codeEl?: HTMLElement;
2425
protected parentEl?: HTMLElement;
2526
private modelValue$?: Subscription;
2627
private observer?: MutationObserver;
2728
private el = inject<ElementRef<HTMLElement>>(ElementRef);
28-
private ngModel = inject<NgModel>(NgModel, {optional: true});
29+
private ngModel = inject<NgModel>(NgModel, { optional: true });
2930
private doc = inject(DOCUMENT);
30-
private cog = inject(HIGHLIGHTJS_CONFIG, {optional: true});
3131
private ngZone = inject(NgZone);
3232

33-
constructor() {
34-
Object.assign(this, this.cog);
35-
}
36-
3733
private escapeHTML(str: string): string {
3834
return (str || '').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&apos;');
3935
}
@@ -49,7 +45,7 @@ export class HighlightJsDirective implements AfterViewInit, OnDestroy {
4945

5046
const isSimple = this.mode() === 'simple';
5147
if (isSimple) {
52-
const lang = this.l();
48+
const lang = this.lang();
5349
if (lang) {
5450
this.codeEl.className = lang;
5551
}

0 commit comments

Comments
 (0)