1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00
pigallery2/frontend/app/settings/_abstract/abstract.settings.service.ts

30 lines
906 B
TypeScript
Raw Normal View History

2017-07-15 20:27:12 +08:00
import {Utils} from "../../../../common/Utils";
import {SettingsService} from "../settings.service";
import {IPrivateConfig} from "../../../../common/config/private/IPrivateConfig";
export abstract class AbstractSettingsService<T> {
public settings: T = <any>{};
public original: T = <any>{};
constructor(protected _settingsService: SettingsService, private sliceFN: (s: IPrivateConfig) => T) {
this.original = Utils.clone(this.settings);
this._settingsService.settings.subscribe(this.onNewSettings);
this.onNewSettings(this._settingsService.settings.value);
}
onNewSettings = (s) => {
this.settings = Utils.clone(this.sliceFN(s));
this.original = Utils.clone(this.settings);
};
public getSettings(): Promise<void> {
return this._settingsService.getSettings();
}
isSupported() {
return true;
}
abstract updateSettings(settings: T): Promise<void>;
2017-07-14 05:39:09 +08:00
}