Skip to content

Commit

Permalink
fix(x): 调整 getApp 导出方式
Browse files Browse the repository at this point in the history
  • Loading branch information
zhetengbiji committed Jan 4, 2025
1 parent 79b9b54 commit 02dad72
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 41 deletions.
26 changes: 6 additions & 20 deletions packages/uni-app-plus/dist/uni.x.runtime.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -2593,22 +2593,6 @@ var appCtx;
var defaultApp = {
globalData: {}
};
class UniAppImpl {
get vm() {
return appCtx;
}
get $vm() {
return appCtx;
}
get globalData() {
var _appCtx;
return ((_appCtx = appCtx) === null || _appCtx === void 0 ? void 0 : _appCtx.globalData) || {};
}
getAndroidApplication() {
return null;
}
}
var $uniApp = new UniAppImpl();
var entryPageState = {
isReady: false,
handledBeforeEntryPageRoutes: false
Expand All @@ -2621,15 +2605,18 @@ function initAppVm(appVm) {
appVm.$vm = appVm;
appVm.$mpType = "app";
}
function getApp$1() {
return $uniApp;
function initUniApp(uniApp) {
uniApp.vm = appCtx;
uniApp.$vm = appCtx;
uniApp.globalData = appCtx.globalData;
}
function registerApp(appVm, nativeApp2) {
function registerApp(appVm, nativeApp2, uniApp) {
initEntryPagePath(nativeApp2);
setNativeApp(nativeApp2);
initVueApp(appVm);
appCtx = appVm;
initAppVm(appCtx);
initUniApp(uniApp);
extend(appCtx, defaultApp);
defineGlobalData(appCtx, defaultApp.globalData);
initService(nativeApp2);
Expand Down Expand Up @@ -7816,7 +7803,6 @@ export {
defineOnApi,
defineSyncApi,
defineTaskApi,
getApp$1 as getApp,
getCurrentPages$1 as getCurrentPages,
initApp,
index$1 as uni
Expand Down
29 changes: 10 additions & 19 deletions packages/uni-app-plus/src/x/framework/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,6 @@ let appCtx: ComponentPublicInstance
const defaultApp = {
globalData: {},
}
class UniAppImpl implements UniApp {
get vm() {
return appCtx
}
get $vm() {
return appCtx
}
get globalData() {
return appCtx?.globalData || {}
}
getAndroidApplication() {
return null
}
}

let $uniApp = new UniAppImpl()

export const entryPageState = {
isReady: false,
Expand Down Expand Up @@ -86,16 +70,22 @@ function initAppVm(appVm: ComponentPublicInstance) {
// TODO uni-app x useI18n
}

export function getApp() {
return $uniApp
export function initUniApp(uniApp: UniApp) {
uniApp.vm = appCtx
uniApp.$vm = appCtx
uniApp.globalData = appCtx.globalData
}

/**
* registerApp
* @param appVm
* @param nativeApp
*/
export function registerApp(appVm: ComponentPublicInstance, nativeApp: IApp) {
export function registerApp(
appVm: ComponentPublicInstance,
nativeApp: IApp,
uniApp: UniApp
) {
if (__DEV__) {
console.log(formatLog('registerApp'))
}
Expand All @@ -118,6 +108,7 @@ export function registerApp(appVm: ComponentPublicInstance, nativeApp: IApp) {

appCtx = appVm
initAppVm(appCtx)
initUniApp(uniApp)

extend(appCtx, defaultApp) // 拷贝默认实现

Expand Down
3 changes: 1 addition & 2 deletions packages/uni-app-plus/src/x/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as uni from './api/index'
import { registerApp as __registerApp, getApp, initApp } from './framework/app'
import { registerApp as __registerApp, initApp } from './framework/app'
import {
definePage as __definePage,
getCurrentPages,
Expand Down Expand Up @@ -28,7 +28,6 @@ import {

export {
uni,
getApp,
getCurrentPages,
__definePage,
__registerApp,
Expand Down

0 comments on commit 02dad72

Please sign in to comment.