perf: Cache SvgModules
It will prevent them to be parsed multiple times.
This commit is contained in:
committed by
József Farkas
parent
10f44f974a
commit
ecd495b7c2
36
shared/src/services/svg-module-provider.service.ts
Normal file
36
shared/src/services/svg-module-provider.service.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
import { SvgModule } from '../components/svg/module';
|
||||
import { KeyboardLayout } from '../keyboard/keyboard-layout.enum';
|
||||
|
||||
@Injectable()
|
||||
export class SvgModuleProviderService {
|
||||
|
||||
private ansiLeft: SvgModule;
|
||||
private isoLeft: SvgModule;
|
||||
private right: SvgModule;
|
||||
|
||||
getSvgModules(layout = KeyboardLayout.ANSI): SvgModule[] {
|
||||
return [this.getRightModule(), this.getLeftModule(layout)];
|
||||
}
|
||||
|
||||
private getLeftModule(layout = KeyboardLayout.ANSI): SvgModule {
|
||||
if (layout === KeyboardLayout.ISO) {
|
||||
if (!this.isoLeft) {
|
||||
this.isoLeft = new SvgModule(require('xml-loader!../../../modules/uhk60-left-half/layout-iso.svg').svg);
|
||||
}
|
||||
return this.isoLeft;
|
||||
}
|
||||
if (!this.ansiLeft) {
|
||||
this.ansiLeft = new SvgModule(require('xml-loader!../../../modules/uhk60-left-half/layout-ansi.svg').svg);
|
||||
}
|
||||
return this.ansiLeft;
|
||||
}
|
||||
|
||||
private getRightModule(): SvgModule {
|
||||
if (!this.right) {
|
||||
this.right = new SvgModule(require('xml-loader!../../../modules/uhk60-right-half/layout.svg').svg);
|
||||
}
|
||||
return this.right;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user