54 lines
1.3 KiB
TypeScript
54 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 { DataApply } from './interfaces/DataApply';
|
|
|
|
export abstract class ControlModel implements DataApply {
|
|
protected data: Record<string, string|number|boolean> = {};
|
|
|
|
public constructor (obj: Record<string, string|number|boolean>) {
|
|
this.data = obj;
|
|
}
|
|
|
|
public get_data (): Record<string, string|number|boolean> {
|
|
return this.data;
|
|
}
|
|
|
|
public apply_object (obj: Record<string, unknown>): void {
|
|
for (const key of Object.keys (obj)) {
|
|
if ([
|
|
'string',
|
|
'number',
|
|
'boolean'
|
|
].indexOf (typeof obj[key]) > -1)
|
|
this.data[key] = obj[key] as string|number|boolean;
|
|
}
|
|
}
|
|
|
|
public apply (da: DataApply): void {
|
|
this.apply_object (da.get_data ());
|
|
}
|
|
|
|
public apply_to (da: DataApply): void {
|
|
da.apply (this);
|
|
}
|
|
|
|
public get (key: string): string|number|boolean {
|
|
return this.data[key];
|
|
}
|
|
|
|
public set (key: string, value: string|number|boolean): void {
|
|
this.data[key] = value;
|
|
}
|
|
|
|
public update (): void {
|
|
this.verify ();
|
|
}
|
|
|
|
public abstract verify(): void;
|
|
}
|