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
@@ -73,6 +73,7 @@ import { SafeStylePipe } from './shared/pipes';
|
|||||||
|
|
||||||
import { CaptureService } from './shared/services/capture.service';
|
import { CaptureService } from './shared/services/capture.service';
|
||||||
import { MapperService } from './shared/services/mapper.service';
|
import { MapperService } from './shared/services/mapper.service';
|
||||||
|
import { SvgModuleProviderService } from './shared/services/svg-module-provider.service';
|
||||||
import { UhkDeviceService } from './services/uhk-device.service';
|
import { UhkDeviceService } from './services/uhk-device.service';
|
||||||
|
|
||||||
import { KeymapEffects, MacroEffects, UserConfigEffects} from './shared/store/effects';
|
import { KeymapEffects, MacroEffects, UserConfigEffects} from './shared/store/effects';
|
||||||
@@ -169,6 +170,7 @@ import { reducer } from '../../shared/src/store/reducers/index';
|
|||||||
UhkDeviceDisconnectedGuard,
|
UhkDeviceDisconnectedGuard,
|
||||||
UhkDeviceInitializedGuard,
|
UhkDeviceInitializedGuard,
|
||||||
UhkDeviceUninitializedGuard,
|
UhkDeviceUninitializedGuard,
|
||||||
|
SvgModuleProviderService,
|
||||||
MapperService,
|
MapperService,
|
||||||
appRoutingProviders,
|
appRoutingProviders,
|
||||||
KeymapEditGuard,
|
KeymapEditGuard,
|
||||||
|
|||||||
@@ -2,11 +2,7 @@ import { Component, EventEmitter, Input, OnInit, Output, ChangeDetectionStrategy
|
|||||||
|
|
||||||
import { Module } from '../../../config-serializer/config-items/Module';
|
import { Module } from '../../../config-serializer/config-items/Module';
|
||||||
import { SvgModule } from '../module';
|
import { SvgModule } from '../module';
|
||||||
|
import { SvgModuleProviderService } from '../../../services/svg-module-provider.service';
|
||||||
enum KeyboardLayout {
|
|
||||||
ANSI,
|
|
||||||
ISO
|
|
||||||
}
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'svg-keyboard',
|
selector: 'svg-keyboard',
|
||||||
@@ -27,13 +23,13 @@ export class SvgKeyboardComponent implements OnInit {
|
|||||||
modules: SvgModule[];
|
modules: SvgModule[];
|
||||||
viewBox: string;
|
viewBox: string;
|
||||||
|
|
||||||
constructor() {
|
constructor(private svgModuleProvider: SvgModuleProviderService) {
|
||||||
this.modules = [];
|
this.modules = [];
|
||||||
this.viewBox = '-520 582 1100 470';
|
this.viewBox = '-520 582 1100 470';
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.modules = this.getSvgModules();
|
this.modules = this.svgModuleProvider.getSvgModules();
|
||||||
}
|
}
|
||||||
|
|
||||||
onKeyClick(moduleId: number, keyId: number, keyTarget: HTMLElement): void {
|
onKeyClick(moduleId: number, keyId: number, keyTarget: HTMLElement): void {
|
||||||
@@ -61,21 +57,4 @@ export class SvgKeyboardComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private getSvgModules(): SvgModule[] {
|
|
||||||
const leftModule = new SvgModule(this.getLeftModule());
|
|
||||||
const rightModule = new SvgModule(this.getRightModule());
|
|
||||||
return [rightModule, leftModule];
|
|
||||||
}
|
|
||||||
|
|
||||||
private getLeftModule(layout = KeyboardLayout.ANSI): any {
|
|
||||||
if (layout === KeyboardLayout.ISO) {
|
|
||||||
return require('xml-loader!../../../../../modules/uhk60-left-half/layout-iso.svg').svg;
|
|
||||||
}
|
|
||||||
return require('xml-loader!../../../../../modules/uhk60-left-half/layout-ansi.svg').svg;
|
|
||||||
}
|
|
||||||
|
|
||||||
private getRightModule(): any {
|
|
||||||
return require('xml-loader!../../../../../modules/uhk60-right-half/layout.svg').svg;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
4
shared/src/keyboard/keyboard-layout.enum.ts
Normal file
4
shared/src/keyboard/keyboard-layout.enum.ts
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
export enum KeyboardLayout {
|
||||||
|
ANSI,
|
||||||
|
ISO
|
||||||
|
}
|
||||||
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -67,6 +67,7 @@ import { SafeStylePipe } from './shared/pipes';
|
|||||||
|
|
||||||
import { CaptureService } from './shared/services/capture.service';
|
import { CaptureService } from './shared/services/capture.service';
|
||||||
import { MapperService } from './shared/services/mapper.service';
|
import { MapperService } from './shared/services/mapper.service';
|
||||||
|
import { SvgModuleProviderService } from './shared/services/svg-module-provider.service';
|
||||||
|
|
||||||
import { KeymapEffects, MacroEffects, UserConfigEffects } from './shared/store/effects';
|
import { KeymapEffects, MacroEffects, UserConfigEffects } from './shared/store/effects';
|
||||||
|
|
||||||
@@ -149,6 +150,7 @@ import { reducer } from '../../shared/src/store/reducers/index';
|
|||||||
EffectsModule.runAfterBootstrap(UserConfigEffects)
|
EffectsModule.runAfterBootstrap(UserConfigEffects)
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
|
SvgModuleProviderService,
|
||||||
MapperService,
|
MapperService,
|
||||||
appRoutingProviders,
|
appRoutingProviders,
|
||||||
KeymapEditGuard,
|
KeymapEditGuard,
|
||||||
|
|||||||
Reference in New Issue
Block a user