import UIRenderView from "./UIRenderView";
import UI from "./UI";


/**
 * @param UI容器 有子对象的界面
 */
export default class UIContainer extends UI{

    protected data:Array<Object>
    protected renders: Array<UIRenderView>=new Array()
    protected sendDataFromRenderCb:Function
    protected isCommonData:boolean=false    //相同的数据更新，只能判断引用

    public async updateData(data?:Array<Object>){
        this.isCommonData=this.data==data&&this.data!=undefined
        this.data=data?.slice()||this.data||new Array()
        await this.onUpdateData(this.data)
    }

    public release(){
        this.renders?.forEach((r)=>r.release())
        super.release()
    }

    //render回调回来
    public addSendDataFromRender(cb:Function){
        this.sendDataFromRenderCb=cb
    }

    //render回调数据
    protected onSendDataFromRender(data?:Object){
        this.sendDataFromRenderCb&&this.sendDataFromRenderCb(data)
    }

}