File

projects/wms-framework/src/lib/utils/ModelProxy.ts

Description

Serves as temporal storage while the real model is not available. When the real model is ready, data can be copied into it.

Index

Methods

Constructor

Private constructor()

Methods

Static copy
copy(source: T, destination: T)
Type parameters :
  • T

Copy data saved in proxy into the actual model.

Parameters :
Name Type Optional Description
source T No

A model proxy.

destination T No

The actual model.

Returns : void
Static create
create()
Type parameters :
  • T

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];
        }
      }
    }
  }
}

result-matching ""

    No results matching ""