import { hasOwnProperty } from "../utils" ; /**
 * 实例的工厂类
 */ export class BaseFactory < T > { protected i : { [ id ] : T ; } = { } ; private pi : { [ id ] : boolean ; } = { } ; param { string } name param { T } intance param { boolean } override return { void | boolean } public add ( name , intance , override = false ) { if ( hasOwnProperty . call ( this . pi , name ) || ! override && this . has ( name ) ) { return this ; } this . i [ name ] = intance ; return this ; } param { String } key return { Boolean } public has ( key ) { return hasOwnProperty . call ( this . i , key ) ; } param { String } key return { T } public get ( key ) { if ( this . has ( key ) ) { return this . i [ key ] ; } return null as any ; } param { String } key public lock ( key ) { if ( this . has ( key ) ) { this . pi [ key ] = true ; } } param key public unLock ( key ) { if ( this . has ( key ) ) { delete this . pi [ key ] ; } } param func public forEach ( func ) { if ( ! func ) { return ; } for ( const key in this . i ) { if ( this . has ( key ) ) { const element = this . i [ key ] ; if ( func ( key , element ) === false ) { break ; } } } } /**
     * 清空当前的hash
     */ public clear ( ) { this . i = { } ; this . pi = { } ; } }