UI: Added clearing cache resources when we change user
This commit is contained in:
parent
2be9a1e1c3
commit
cc3e5681a8
@ -30,6 +30,9 @@ import { IModulesMap } from '@modules/common/modules-map.models';
|
|||||||
import { TbResourceId } from '@shared/models/id/tb-resource-id';
|
import { TbResourceId } from '@shared/models/id/tb-resource-id';
|
||||||
import { isObject } from '@core/utils';
|
import { isObject } from '@core/utils';
|
||||||
import { AuthService } from '@core/auth/auth.service';
|
import { AuthService } from '@core/auth/auth.service';
|
||||||
|
import { select, Store } from '@ngrx/store';
|
||||||
|
import { selectIsAuthenticated } from '@core/auth/auth.selectors';
|
||||||
|
import { AppState } from '@core/core.state';
|
||||||
|
|
||||||
declare const System;
|
declare const System;
|
||||||
|
|
||||||
@ -50,9 +53,12 @@ export class ResourcesService {
|
|||||||
private anchor = this.document.getElementsByTagName('head')[0] || this.document.getElementsByTagName('body')[0];
|
private anchor = this.document.getElementsByTagName('head')[0] || this.document.getElementsByTagName('body')[0];
|
||||||
|
|
||||||
constructor(@Inject(DOCUMENT) private readonly document: any,
|
constructor(@Inject(DOCUMENT) private readonly document: any,
|
||||||
|
protected store: Store<AppState>,
|
||||||
private compiler: Compiler,
|
private compiler: Compiler,
|
||||||
private http: HttpClient,
|
private http: HttpClient,
|
||||||
private injector: Injector) {}
|
private injector: Injector) {
|
||||||
|
this.store.pipe(select(selectIsAuthenticated)).subscribe(() => this.clearCache());
|
||||||
|
}
|
||||||
|
|
||||||
public loadResource(url: string): Observable<any> {
|
public loadResource(url: string): Observable<any> {
|
||||||
if (this.loadedResources[url]) {
|
if (this.loadedResources[url]) {
|
||||||
@ -270,4 +276,20 @@ export class ResourcesService {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private deleteFromSystemJS(keys: string[]) {
|
||||||
|
keys.forEach(item => {
|
||||||
|
if (System.has(item)) {
|
||||||
|
System.delete(item);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private clearCache() {
|
||||||
|
this.deleteFromSystemJS(Object.keys(this.loadedModules));
|
||||||
|
this.loadedModules = {};
|
||||||
|
|
||||||
|
this.deleteFromSystemJS(Object.keys(this.loadedModulesAndFactories));
|
||||||
|
this.loadedModulesAndFactories = {};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user