Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(runtime): 允许挂载东西在小程序 app 全局对象上 #8448

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/taro-runtime/src/dsl/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,6 @@ export interface AppInstance extends Show {
onLaunch? (options?: string): void
mount? (component: React.ComponentClass | ComponentOptions<VueCtor> | Vue3Component, id: string, cb: () => void): void
unmount? (id: string, cb: () => void): void
onPageNotFound? (res: any): void
optionsExtraKeys?: string[]
}
19 changes: 19 additions & 0 deletions packages/taro-runtime/src/dsl/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down