47 lines
1.2 KiB
TypeScript
47 lines
1.2 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 ();
|
|
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;
|
|
}
|