From e0aff5f6f210c0006cdafbf593d2f375c9c972e4 Mon Sep 17 00:00:00 2001 From: chenjiajian <798095202@qq.com> Date: Tue, 5 Jan 2021 19:53:31 +0800 Subject: [PATCH] =?UTF-8?q?feat(runtime):=20=E5=85=81=E8=AE=B8=E6=8C=82?= =?UTF-8?q?=E8=BD=BD=E4=B8=9C=E8=A5=BF=E5=9C=A8=E5=B0=8F=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=20app=20=E5=85=A8=E5=B1=80=E5=AF=B9=E8=B1=A1=E4=B8=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-runtime/src/dsl/instance.ts | 2 ++ packages/taro-runtime/src/dsl/react.ts | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/packages/taro-runtime/src/dsl/instance.ts b/packages/taro-runtime/src/dsl/instance.ts index cc78e18b5884..85fda6c357bb 100644 --- a/packages/taro-runtime/src/dsl/instance.ts +++ b/packages/taro-runtime/src/dsl/instance.ts @@ -76,4 +76,6 @@ export interface AppInstance extends Show { onLaunch? (options?: string): void mount? (component: React.ComponentClass | ComponentOptions | Vue3Component, id: string, cb: () => void): void unmount? (id: string, cb: () => void): void + onPageNotFound? (res: any): void + optionsExtraKeys?: string[] } diff --git a/packages/taro-runtime/src/dsl/react.ts b/packages/taro-runtime/src/dsl/react.ts index 0cf5a784b61d..064ff282b92b 100644 --- a/packages/taro-runtime/src/dsl/react.ts +++ b/packages/taro-runtime/src/dsl/react.ts @@ -230,6 +230,25 @@ export function createReactApp (App: React.ComponentClass, react: typeof React, // eslint-disable-next-line react/no-render-return-value wrapper = ReactDOM.render(R.createElement(AppWrapper), document.getElementById('app')) const app = ref.current + + // For taroize + // 把 App Class 上挂载的额外属性同步到全局 app 对象中 + if (app?.optionsExtraKeys?.length) { + app.optionsExtraKeys.forEach(key => { + Object.defineProperty(this, key, { + configurable: true, + enumerable: true, + get () { + return app[key] + }, + set (value) { + app[key] = value + } + }) + }) + } + this.$app = app + if (app != null && isFunction(app.onLaunch)) { app.onLaunch(options) }