import {Singleton} from "../utils/Singleton";

/*
* name;
*/
export class PanelResDic extends Laya.EventDispatcher
{
    private static ins:PanelResDic;

    private static _mapviewDict:any={};

	constructor() 
	{
        super();
        PanelResDic.ins = this;
	}
	
    public static get Instance(): PanelResDic
	{
        if(PanelResDic.ins == null)
        {
            return new PanelResDic();
        }
        return PanelResDic.ins;
    }

    public static getView( viewkey:string ):any
    {
        if( !PanelResDic._mapviewDict[viewkey] )
        {
            throw "err0 未绑定的viewkey:" + viewkey;
        }
        return PanelResDic._mapviewDict[viewkey];
    }
    
    
    public getSingleTon(ref:any):any
	{
        return Singleton.Instance(ref);
    }
    
    

    public mapView( viewkey:string,ref:any ):void
    {
        if( !PanelResDic._mapviewDict[viewkey] )
        {
            PanelResDic._mapviewDict[viewkey] = ref;
            ref.key = viewkey;
        }
    }

    

    public AgencyAdd(ref:any):void
	{
        Singleton.create(ref);
    }

    public AgencyClear(ref:any):void
	{
        Singleton.remove(ref);
    }
}