refactor(store): Refactor reducer initialisation (#298)
* refactor(store): Refactor reducer initialization Refactored the ngrx/store reducer initialization, because hard to extend the original solution. Bad practise the object initialization inside the components / services. The new solution use angular DI everywhere. Separated the web and electron configuration store. * Media key support (#294) * Introduce type for KeystrokeAction * Increment dataModelVersion New property 'type' for KeystrokeAction * Mapping for media keys * Media key selecting support for KeypressTab * refactor: Use more meaningful name (selectedScancodeOption) * Store the keystroke type in key action type instead of a new field * Fix NoneAction validation Fixes #301 * Update electron version It fixes electron build. The types are part of the electron package itself. * Fix keystroke selection when additional field is given but no scancode (#306) * Additional media keys with icons (#307) * Add missing scancodes for media keystrokes * Use icons for media keys * Fix media scancodes. * Create README.md * build: upgrade electron and typescript version Electron contains the typings files. * refactor(store): Refactor reducer initialization Refactored the ngrx/store reducer initialization, because hard to extend the original solution. Bad practise the object initialization inside the components / services. The new solution use angular DI everywhere. Separated the web and electron configuration store. * build: upgrade electron and typescript version Electron contains the typings files. * fix(store): Remove the I prefix from IDataStorageRepositoryService * fix(store): fix observer operator import * fix(store): Add missing rxjs imports to user-config effect * fix(store): Add missing rxjs imports to keymap effect
This commit is contained in:
committed by
László Monda
parent
679e20d915
commit
367bc42457
12
shared/src/services/datastorage-repository.service.ts
Normal file
12
shared/src/services/datastorage-repository.service.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { InjectionToken } from '@angular/core';
|
||||
|
||||
import { UserConfiguration } from '../config-serializer/config-items/UserConfiguration';
|
||||
|
||||
export interface DataStorageRepositoryService {
|
||||
|
||||
getConfig(): UserConfiguration;
|
||||
|
||||
saveConfig(config: UserConfiguration): void;
|
||||
}
|
||||
|
||||
export let DATA_STORAGE_REPOSITORY = new InjectionToken('dataStorage-repository');
|
||||
16
shared/src/services/default-user-configuration.service.ts
Normal file
16
shared/src/services/default-user-configuration.service.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { UserConfiguration } from '../config-serializer/config-items/UserConfiguration';
|
||||
|
||||
@Injectable()
|
||||
export class DefaultUserConfigurationService {
|
||||
private _defaultConfig: UserConfiguration;
|
||||
|
||||
constructor() {
|
||||
this._defaultConfig = new UserConfiguration()
|
||||
.fromJsonObject(require('json-loader!../config-serializer/user-config.json'));
|
||||
}
|
||||
|
||||
getDefault(): UserConfiguration {
|
||||
return this._defaultConfig;
|
||||
}
|
||||
}
|
||||
27
shared/src/services/local-datastorage-repository.service.ts
Normal file
27
shared/src/services/local-datastorage-repository.service.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { UserConfiguration } from '../config-serializer/config-items/UserConfiguration';
|
||||
import { DataStorageRepositoryService } from './datastorage-repository.service';
|
||||
import { DefaultUserConfigurationService } from './default-user-configuration.service';
|
||||
|
||||
@Injectable()
|
||||
export class LocalDataStorageRepositoryService implements DataStorageRepositoryService {
|
||||
constructor(private defaultUserConfigurationService: DefaultUserConfigurationService) { }
|
||||
|
||||
getConfig(): UserConfiguration {
|
||||
const configJsonString = localStorage.getItem('config');
|
||||
let config: UserConfiguration;
|
||||
|
||||
if (configJsonString) {
|
||||
const configJsonObject = JSON.parse(configJsonString);
|
||||
if (configJsonObject.dataModelVersion === this.defaultUserConfigurationService.getDefault().dataModelVersion) {
|
||||
config = new UserConfiguration().fromJsonObject(configJsonObject);
|
||||
}
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
saveConfig(config: UserConfiguration): void {
|
||||
localStorage.setItem('config', JSON.stringify(config.toJsonObject()));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user