File

projects/wms-framework/src/lib/regionsframework/RegionAdapterBase.ts

Index

Methods

Methods

Public AttachBehaviors
AttachBehaviors(region: IRegion, target: any)
Parameters :
Name Type Optional
region IRegion No
target any No
Returns : void
import { ArgumentNullException } from '../baseframework';
import { IRegion } from './IRegion';
import { IRegionAdapter } from './IRegionAdapter';
import { IRegionBehaviorFactory } from './IRegionBehaviorFactory';

export class RegionAdapterBaseUnTyped {
  public AttachBehaviors(region: IRegion, target: any) {}
}

/**
 * RegionAdapterBase abstract class.
 *
 * @export
 * @abstract
 * @class RegionAdapterBase
 * @extends {RegionAdapterBaseUnTyped}
 * @implements {IRegionAdapter}
 * @template T
 * @wType Microsoft.Practices.Prism.Regions.RegionAdapterBase`1
 */
export abstract class RegionAdapterBase<T>
  extends RegionAdapterBaseUnTyped
  implements IRegionAdapter
{
  RegionBehaviorFactory: IRegionBehaviorFactory;

  constructor(factory: IRegionBehaviorFactory) {
    super();
    this.RegionBehaviorFactory = factory;
  }

  Initialize(regionTarget: object, regionName: string): IRegion {
    if (regionName == null) {
      throw new ArgumentNullException('regionName');
    }
    const region = this.CreateRegion();
    region.Name = regionName;
    this.Adapt(region, regionTarget as any);
    this.AttachBehaviors(region, regionTarget);
    this.AttachDefaultBehaviors(region, <any>regionTarget);
    return region;
  }

  protected abstract CreateRegion(): IRegion;
  protected abstract Adapt(region: IRegion, regionTarget: T): void;

  /**
   * Attach defaults behavior to region
   *
   * @protected
   * @param {IRegion} region
   * @param {T} regionTarget
   * @memberof RegionAdapterBase
   */
  protected AttachDefaultBehaviors(region: IRegion, regionTarget: T): void {
    if (region == null) {
      throw new ArgumentNullException('region');
    }
    if (regionTarget == null) {
      throw new ArgumentNullException('regionTarget');
    }
    const behaviorFactory = this.RegionBehaviorFactory;
    if (behaviorFactory != null) {
      for (const behaviorKey of behaviorFactory) {
        let behavior = behaviorFactory.CreateFromKey(behaviorKey);
        region.Behaviors.Add(behaviorKey, behavior);
      }
    }
  }
}

result-matching ""

    No results matching ""