projects/wms-framework/src/lib/utils/ModelProxy.ts
Serves as temporal storage while the real model is not available. When the real model is ready, data can be copied into it.
Methods |
Private
constructor()
|
Static copy | ||||||||||||
copy(source: T, destination: T)
|
||||||||||||
Type parameters :
|
||||||||||||
Copy data saved in proxy into the actual model.
Parameters :
Returns :
void
|
Static create |
create()
|
Type parameters :
|
Returns a new model proxy.
Returns :
T
|
import { CanvasModel } from '../models/controls/CanvasModel';
/**
* Serves as temporal storage while the real model is not available.
* When the real model is ready, data can be copied into it.
*/
export class ModelProxy {
private constructor() {}
/**
* Returns a new model proxy.
*/
static create<T>(): T {
return new ModelProxy() as unknown as T;
}
/**
* Copy data saved in proxy into the actual model.
* @param source A model proxy.
* @param destination The actual model.
*/
static copy<T>(source: T, destination: T): void {
for (const key in source) {
const keyname = key.toString();
if (source.hasOwnProperty(keyname)) {
if (
keyname === CanvasModel.ZIndexProperty.name &&
(<any>destination).setValue
) {
(<any>destination).setValue(
CanvasModel.ZIndexProperty,
source[keyname]
);
} else {
destination[keyname] = source[keyname];
}
}
}
}
}