Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions packages/primeng/src/basecomponent/basecomponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export class BaseComponent<PT = any> implements Lifecycle {

private _themeScopedListener: () => void;

private themeChangeListenerMap: Map<string, any> = new Map();

/******************** Inputs ********************/

/**
Expand Down Expand Up @@ -164,35 +166,31 @@ export class BaseComponent<PT = any> implements Lifecycle {
// watch _dt_ changes
effect((onCleanup) => {
if (this.document && !isPlatformServer(this.platformId)) {
ThemeService.off('theme:change', this._themeScopedListener);

if (this.dt()) {
this._loadScopedThemeStyles(this.dt());
this._themeScopedListener = () => this._loadScopedThemeStyles(this.dt());
this._themeChangeListener(this._themeScopedListener);
this._themeChangeListener('_themeScopedListener', this._themeScopedListener);
} else {
this._unloadScopedThemeStyles();
}
}

onCleanup(() => {
ThemeService.off('theme:change', this._themeScopedListener);
this._offThemeChangeListener('_themeScopedListener');
});
});

// watch _unstyled_ changes
effect((onCleanup) => {
if (this.document && !isPlatformServer(this.platformId)) {
ThemeService.off('theme:change', this._loadCoreStyles);

if (!this.$unstyled()) {
this._loadCoreStyles();
this._themeChangeListener(this._loadCoreStyles); // Update styles with theme settings
this._themeChangeListener('_loadCoreStyles', this._loadCoreStyles); // Update styles with theme settings
}
}

onCleanup(() => {
ThemeService.off('theme:change', this._loadCoreStyles);
this._offThemeChangeListener('_loadCoreStyles');
});
});

Expand Down Expand Up @@ -331,7 +329,7 @@ export class BaseComponent<PT = any> implements Lifecycle {

private _loadStyles() {
this._load();
this._themeChangeListener(() => this._load());
this._themeChangeListener('_load', () => this._load());
}

private _loadGlobalStyles() {
Expand Down Expand Up @@ -394,15 +392,25 @@ export class BaseComponent<PT = any> implements Lifecycle {
this.scopedStyleEl?.remove();
}

private _themeChangeListener(callback = () => {}) {
private _themeChangeListener(id: string, callback = () => {}) {
this._offThemeChangeListener(id);
Base.clearLoadedStyleNames();
ThemeService.on('theme:change', callback.bind(this));
const hold = callback.bind(this);
this.themeChangeListenerMap.set(id, hold);
ThemeService.on('theme:change', hold);
}

private _removeThemeListeners() {
ThemeService.off('theme:change', this._loadCoreStyles);
ThemeService.off('theme:change', this._load);
ThemeService.off('theme:change', this._themeScopedListener);
this._offThemeChangeListener('_themeScopedListener');
this._offThemeChangeListener('_loadCoreStyles');
this._offThemeChangeListener('_load');
}

private _offThemeChangeListener(id: string) {
if (this.themeChangeListenerMap.has(id)) {
ThemeService.off('theme:change', this.themeChangeListenerMap.get(id));
this.themeChangeListenerMap.delete(id);
}
}

/********** Passthrough **********/
Expand Down
6 changes: 0 additions & 6 deletions packages/primeng/src/dynamicdialog/dynamicdialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,12 +561,6 @@ export class DynamicDialog extends BaseComponent<DialogPassThrough> {
}

onDestroy() {
if (this.componentRef && typeof this.componentRef.destroy === 'function') {
this.componentRef.destroy();
}
}

ngOnDestroy() {
this.onContainerDestroy();
if (this.componentRef && typeof this.componentRef.destroy === 'function') {
this.componentRef.destroy();
Expand Down
Loading