/* * 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 , May 2020 */ import { Persistent } from './Persistent'; export abstract class ControlModel extends Persistent { public constructor (obj?: Record) { 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 { return super.to_object () as Record; } 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; }