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CAAC;IAED,mBAAmB;IACnB,iBAAiB;QACb,IAAI,CAAC,eAAe,GAAG,KAAK,CAAC;QAC7B,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;YAC9B,CAAC,CAAC,sBAAsB,EAAE,CAAC;QAC/B,CAAC,CAAC,CAAC;IACP,CAAC;IAED,iBAAiB;QACb,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;QAC5B,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;YAC9B,CAAC,CAAC,sBAAsB,EAAE,CAAC;QAC/B,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AA/DD,8BA+DC","file":"","sourceRoot":"/","sourcesContent":["import { View, Subview, OnSubviewCreated } from \"./ViewBase\";\nimport { CompositeDisposable } from \"simba-eventkit\";\n\nlet presenterViewFactory: (<P, V extends View, PR extends Presenter<P, V>>(presenterCls: { new(): PR, uuid: string }) => Promise<V>) & { preloadView: (presenterCls: { new(): Presenter, uuid: string }) => Promise<void> };\n\nexport function setPresenterViewFactory(factory: typeof presenterViewFactory) {\n presenterViewFactory = factory;\n}\n\nlet subpresenterFactory: (subview: Subview) => Subpresenter;\n\nexport function setSubpresenterwFactory(factory: (subview: Subview) => Subpresenter) {\n subpresenterFactory = factory;\n}\n\nlet currentCreatingPresenter: Presenter<any, any> | undefined;\n/**\n * 加载预制与Presenter\n * @param presenterCls \n * @returns \n */\nexport async function createPresenter<P, V extends View, PR extends Presenter<P, V>>(presenterCls: { new(): PR, uuid: string }): Promise<PR> {\n await presenterViewFactory.preloadView(presenterCls as any);\n if (currentCreatingPresenter) {\n console.warn(\"create presenter simultaneously will cause sub presenters error!\");\n }\n let presenter = currentCreatingPresenter = new presenterCls;\n let view = await presenterViewFactory<P, V, PR>(presenterCls);\n presenter.attachView(view);\n currentCreatingPresenter = undefined;\n return presenter;\n}\n\nOnSubviewCreated.on((subview) => {\n if (!currentCreatingPresenter) {\n return;\n }\n let presenter = subpresenterFactory(subview);\n presenter.owner = currentCreatingPresenter;\n (currentCreatingPresenter as any)._subpresenters.push(presenter);\n});\n\nexport type PresenterParamType<T> = T extends Presenter<infer U, any> ? U : any;\n\nclass PresenterBase {\n protected _disposable: CompositeDisposable;\n \n onShow() {\n\n }\n\n onHide() {\n\n }\n}\n\nexport class Subpresenter<V extends Subview = Subview, Owner extends Presenter<any, any> = Presenter<any, any>> extends PresenterBase {\n owner: Owner;\n _view: Subview;\n\n get view() { return this._view as V; }\n\n attachView(view: V) {\n this._view = view;\n }\n\n onOpen() {\n this._disposable = new CompositeDisposable;\n this._disposable.add(this._view.onShow.on(() => this.onShow()));\n this._disposable.add(this._view.onHide.on(() => this.onHide()));\n \n }\n\n onClose() {\n this._disposable.dispose();\n }\n\n onOwnerShow() {\n\n }\n\n onOwnerHide() {\n\n }\n\n onOwnerEnterForeground() {\n\n }\n\n onOwnerEnterBackground() {\n\n }\n}\n\nexport class Presenter<P = undefined, V extends View = View> extends PresenterBase {\n protected _view: V;\n protected _isInBackground = false;\n protected _subpresenters: Subpresenter[] = [];\n\n get view() { return this._view as V; }\n \n open = (parent: View, props: P) => {\n this._view.open(parent);\n this.onOpen(props);\n }\n\n attachView(view: V) {\n this._view = view;\n }\n\n onOpen(props: P) {\n this._disposable = new CompositeDisposable;\n this._disposable.add(this._view.onClose.on(() => this.onClose()));\n this._disposable.add(this._view.onShow.on(() => this.onShow()));\n this._disposable.add(this._view.onHide.on(() => this.onHide()));\n this._subpresenters.forEach((p) => {\n p.onOpen();\n \n });\n if(CC_DEV){\n globalThis[`${this._view['node']['name']}`] = this;\n }\n }\n\n onClose() {\n this._disposable.dispose();\n this._subpresenters.forEach((p) => {\n p.onClose();\n });\n }\n\n onShow() {\n this._subpresenters.forEach((p) => {\n p.onOwnerShow();\n });\n }\n\n onHide() {\n this._subpresenters.forEach((p) => {\n p.onOwnerHide();\n });\n }\n\n /**presenter进入前景 */\n onEnterForeground() {\n this._isInBackground = false;\n this._subpresenters.forEach((p) => {\n p.onOwnerEnterForeground();\n });\n }\n\n onEnterBackground() {\n this._isInBackground = true;\n this._subpresenters.forEach((p) => {\n p.onOwnerEnterBackground();\n });\n }\n}\n"]}