modelling/lib/ControlModel.ts
Timo Hocker 433b2b5b27 fix
2020-05-05 11:48:46 +02:00

49 lines
1.3 KiB
TypeScript

/*
* Copyright (C) Sapphirecode - All Rights Reserved
* This file is part of Modelling which is released under MIT.
* See file 'LICENSE' for full license details.
* Created by Timo Hocker <timo@scode.ovh>, May 2020
*/
import { Persistent } from './Persistent';
export abstract class ControlModel extends Persistent {
public constructor (obj?: Record<string, string|number|boolean>) {
super ();
this.define_properties ();
for (const prop of Object.keys (this.properties)) {
if ([
'string',
'number',
'boolean'
].indexOf (this.properties[prop]) < 0) {
throw new Error (
'property types have to be either string, number or boolean'
);
}
}
if (typeof obj !== 'undefined')
this.assign_object (obj);
}
public to_object (): Record<string, string|number|boolean> {
return super.to_object () as Record<string, string|number|boolean>;
}
public get (key: string): string|number|boolean {
return super.get (key) as string|number|boolean;
}
public set (key: string, value: string|number|boolean): void {
super.set (key, value);
}
public update (): void {
this.verify ();
}
public abstract verify(): void;
protected abstract define_properties(): void;
}