projects/wms-framework/src/lib/regionsframework/IRegionBehaviorFactory.ts
        
Region behavior factory
| Properties | 
| 
 | 
| Methods | 
| constructor(container: DependencyContainer) | ||||||
| 
                                    Parameters :
                                     
 | 
| Private behaviors | 
| Type : SimpleDictionary<string | RuntimeTypeInfo> | 
| Default value : new SimpleDictionary() | 
| AddIfMissing | |||||||||
| AddIfMissing(key: string, type: RuntimeTypeInfo) | |||||||||
| Adds new behavior with the given key 
                        Parameters :
                         
 
                        Returns :          void | 
| ContainsKey | ||||||
| ContainsKey(key: string) | ||||||
| Verifies if the given key is already used in the behaviors collection 
                        Parameters :
                         
 
                        Returns :          boolean{boolean} | 
| CreateFromKey | ||||||
| CreateFromKey(key: string) | ||||||
| Creates a new behavior from the given key 
                        Parameters :
                         
 
                        Returns :          IRegionBehavior{IRegionBehavior} | 
| () | 
| 
                        Returns :      Iterator<string, any, undefined> | 
import { RuntimeTypeInfo, SimpleDictionary } from '../baseframework';
import { IRegionBehavior } from './IRegionBehavior';
import { DependencyContainer, inject, injectable } from 'tsyringe';
import { containerInjectionToken } from './injectionTokens';
/**
 * Interface for behavior factories
 *
 * @export
 * @interface IRegionBehaviorFactory
 * @wInterface Microsoft.Practices.Prism.Regions.IRegionBehaviorFactory
 */
export interface IRegionBehaviorFactory extends Iterable<string> {
  /**
   *  Add a new behavior
   *
   * @param {string} key
   * @param {RuntimeTypeInfo} type
   * @memberof IRegionBehaviorFactory
   */
  AddIfMissing(key: string, type: RuntimeTypeInfo);
  /**
   *  Verifies if the given key is associated to a registered region
   *
   * @param {string} key
   * @return {*}  {boolean}
   * @memberof IRegionBehaviorFactory
   */
  ContainsKey(key: string): boolean;
  /**
   *  Create a behavior from a key
   *
   * @param {string} key
   * @return {*}  {IRegionBehavior}
   * @memberof IRegionBehaviorFactory
   */
  CreateFromKey(key: string): IRegionBehavior;
}
/**
 *  Region behavior factory
 *
 * @export
 * @class RegionBehaviorFactory
 * @implements {IRegionBehaviorFactory}
 * @wType Microsoft.Practices.Prism.Regions.RegionBehaviorFactory
 */
@injectable()
export class RegionBehaviorFactory implements IRegionBehaviorFactory {
  private behaviors: SimpleDictionary<string, RuntimeTypeInfo> =
    new SimpleDictionary();
  constructor(
    @inject(containerInjectionToken) private container: DependencyContainer
  ) {}
  [Symbol.iterator](): Iterator<string, any, undefined> {
    return this.behaviors.keys[Symbol.iterator]();
  }
  /**
   *  Adds new behavior with the given key
   *
   * @param {string} key
   * @param {RuntimeTypeInfo} type
   * @memberof RegionBehaviorFactory
   */
  AddIfMissing(key: string, type: RuntimeTypeInfo) {
    if (!this.behaviors.containsKey(key)) {
      this.behaviors.setItem(key, type);
    }
  }
  /**
   *  Verifies if the given key is already used in the behaviors collection
   *
   * @param {string} key
   * @return {*}  {boolean}
   * @memberof RegionBehaviorFactory
   */
  ContainsKey(key: string): boolean {
    return this.behaviors.containsKey(key);
  }
  /**
   *  Creates a new behavior from the given key
   *
   * @param {string} key
   * @return {*}  {IRegionBehavior}
   * @memberof RegionBehaviorFactory
   */
  CreateFromKey(key: string): IRegionBehavior {
    const type = this.behaviors.getItem(key);
    if (type) {
      return this.container.resolve(type.JSType);
    } else {
      return null;
    }
  }
}