Skip to content

Commit

Permalink
Merge branch 'fix-drn' of https://github.com/didi/mpx into fix-drn
Browse files Browse the repository at this point in the history
  • Loading branch information
lareinayanyu committed Dec 19, 2024
2 parents b839c33 + 0b04908 commit 2eb1a86
Show file tree
Hide file tree
Showing 63 changed files with 1,109 additions and 892 deletions.
2 changes: 1 addition & 1 deletion docs-vuepress/api/compile.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ mode 为 Mpx 编译的目标平台, 目前支持的有微信小程序(wx)\支
// 项目 package.json
{
"script": {
"build:cross": "mpx-cli-service build:mp --targets=wx,ali"
"build:cross": "mpx-cli-service build --targets=wx,ali"
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion docs-vuepress/guide/advance/platform.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ new MpxwebpackPlugin({
// 项目 package.json
{
"script": {
"build:cross": "mpx-cli-service build:mp --targets=wx,ali"
"build:cross": "mpx-cli-service build --targets=wx,ali"
}
}
```
Expand Down
4 changes: 3 additions & 1 deletion docs-vuepress/guide/basic/start.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
npm i -g @mpxjs/cli
```

> @mpxjs/cli文档 https://github.com/mpx-ecology/mpx-cli
## 创建项目安装依赖

在当前目录下创建mpx项目。
Expand All @@ -29,7 +31,7 @@ npm install
## 编译构建

使用npm script执行mpx的编译构建,在开发模式下我们执行watch命令,将项目源码构建输出到`dist/${平台目录}`下,并且监听源码的改动进行重新编译。
使用npm script执行mpx的编译构建,在开发模式下我们执行serve命令,将项目源码构建输出到`dist/${平台目录}`下,并且监听源码的改动进行重新编译。

```shell
npm run serve
Expand Down
2 changes: 1 addition & 1 deletion docs-vuepress/guide/platform/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ new MpxwebpackPlugin({
// 项目 package.json
{
"script": {
"build:cross": "mpx-cli-service build:mp --targets=wx,ali,ios,android"
"build:cross": "mpx-cli-service build --targets=wx,ali,ios,android"
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion examples/mpx-webview/H5/webviewbridge.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions packages/api-proxy/@types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ export const createVideoContext: WechatMiniprogram.Wx['createVideoContext']
export const onWindowResize: WechatMiniprogram.Wx['onWindowResize']
export const offWindowResize: WechatMiniprogram.Wx['offWindowResize']
export const createAnimation: WechatMiniprogram.Wx['createAnimation']
export const vibrateShort: WechatMiniprogram.Wx['vibrateShort']
export const vibrateLong: WechatMiniprogram.Wx['vibrateLong']
export const getExtConfig: WechatMiniprogram.Wx['getExtConfig']
export const getExtConfigSync: WechatMiniprogram.Wx['getExtConfigSync']
export const openLocation: WechatMiniprogram.Wx['openLocation']
export const chooseLocation: WechatMiniprogram.Wx['chooseLocation']

declare const install: (...args: any) => any

Expand Down
37 changes: 26 additions & 11 deletions packages/api-proxy/src/platform/api/app/index.web.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,27 @@ import { isBrowser, isReact } from '@mpxjs/utils'
global.__mpxAppCbs = global.__mpxAppCbs || {
show: [],
hide: [],
error: []
error: [],
rejection: []
}

function off (cbs, cb) {
if (cb) {
const idx = cbs.indexOf(cb)
if (idx > -1) cbs.splice(idx, 1)
} else {
cbs.length = 0
}
}

function onUnhandledRejection (callback) {
if (isBrowser || isReact) {
global.__mpxAppCbs.rejection.push(callback)
}
}

function offUnhandledRejection (callback) {
off(global.__mpxAppCbs.rejection, callback)
}

function onError (callback) {
Expand All @@ -14,9 +33,7 @@ function onError (callback) {
}

function offError (callback) {
const cbs = global.__mpxAppCbs.error
const index = cbs.indexOf(callback)
if (index > -1) cbs.splice(index, 1)
off(global.__mpxAppCbs.error, callback)
}

function onAppShow (callback) {
Expand All @@ -26,9 +43,7 @@ function onAppShow (callback) {
}

function offAppShow (callback) {
const cbs = global.__mpxAppCbs.show
const index = cbs.indexOf(callback)
if (index > -1) cbs.splice(index, 1)
off(global.__mpxAppCbs.show, callback)
}

function onAppHide (callback) {
Expand All @@ -38,9 +53,7 @@ function onAppHide (callback) {
}

function offAppHide (callback) {
const cbs = global.__mpxAppCbs.hide
const index = cbs.indexOf(callback)
if (index > -1) cbs.splice(index, 1)
off(global.__mpxAppCbs.hide, callback)
}

export {
Expand All @@ -49,5 +62,7 @@ export {
offAppShow,
offAppHide,
onError,
offError
offError,
onUnhandledRejection,
offUnhandledRejection
}
4 changes: 2 additions & 2 deletions packages/api-proxy/src/platform/api/toast/rnToast.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const styles = StyleSheet.create({
backgroundColor: 'rgba(20, 20, 20, 0.7)',
paddingTop: 15,
paddingBottom: 15,
paddingLeft: 10,
paddingRight: 10,
paddingLeft: 20,
paddingRight: 20,
borderRadius: 5,
display: 'flex',
flexDirection: 'column',
Expand Down
6 changes: 5 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@react-navigation/stack": "^7.0.4",
"react": "*",
"react-native": "*",
"promise": "^8.3.0",
"react-native-gesture-handler": "^2.19.0",
"react-native-linear-gradient": "^2.8.3",
"react-native-safe-area-context": "^4.14.0",
Expand Down Expand Up @@ -61,6 +62,9 @@
"react-native": {
"optional": true
},
"promise": {
"optional": true
},
"@react-navigation/native": {
"optional": true
},
Expand Down Expand Up @@ -106,4 +110,4 @@
},
"sideEffects": false,
"gitHead": "2d37697869b9bdda3efab92dda8c910b68fd05c0"
}
}
2 changes: 1 addition & 1 deletion packages/core/src/core/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import {
} from './innerLifecycle'
import contextMap from '../dynamic/vnode/context'
import { getAst } from '../dynamic/astCache'
import { inject, provide } from '../platform/export/apiInject'
import { inject, provide } from '../platform/export/inject'

let uid = 0

Expand Down
1 change: 0 additions & 1 deletion packages/core/src/external/vue.js

This file was deleted.

6 changes: 0 additions & 6 deletions packages/core/src/external/vue.web.js

This file was deleted.

17 changes: 3 additions & 14 deletions packages/core/src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import Vue from './external/vue'

import { error, diffAndCloneA, hasOwn, makeMap } from '@mpxjs/utils'
import { APIs, InstanceAPIs } from './platform/export/api'

import { createI18n } from './platform/builtInMixins/i18nMixin'
import { init } from './platform/env/index'

export * from './platform/export/index'

Expand Down Expand Up @@ -123,10 +122,6 @@ function factory () {

Object.assign(Mpx, APIs)
Object.assign(Mpx.prototype, InstanceAPIs)
// 输出web时在mpx上挂载Vue对象
if (__mpx_mode__ === 'web') {
Mpx.__vue = Vue
}
return Mpx
}

Expand Down Expand Up @@ -156,12 +151,6 @@ Mpx.config = {
rnConfig: {}
}

global.__mpx = Mpx

if (__mpx_mode__ !== 'web') {
if (global.i18n) {
Mpx.i18n = createI18n(global.i18n)
}
}
init(Mpx)

export default Mpx
9 changes: 3 additions & 6 deletions packages/core/src/platform/createApp.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,6 @@ export default function createApp (option, config = {}) {
}
}

global.__mpxAppCbs = global.__mpxAppCbs || {
show: [],
hide: [],
error: []
}

global.__mpxAppLaunched = false

global.__mpxAppFocusedState = ref('show')
Expand Down Expand Up @@ -137,6 +131,9 @@ export default function createApp (option, config = {}) {
if (defaultOptions.onError) {
global.__mpxAppCbs.error.push(defaultOptions.onError.bind(instance))
}
if (defaultOptions.onUnhandledRejection) {
global.__mpxAppCbs.rejection.push(defaultOptions.onUnhandledRejection.bind(instance))
}

const changeSubscription = ReactNative.AppState.addEventListener('change', (currentState) => {
if (currentState === 'active') {
Expand Down
10 changes: 4 additions & 6 deletions packages/core/src/platform/createApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { makeMap, spreadProp, isBrowser } from '@mpxjs/utils'
import { mergeLifecycle } from '../convertor/mergeLifecycle'
import { LIFECYCLE } from '../platform/patch/lifecycle/index'
import Mpx from '../index'
import { initAppProvides } from './export/apiInject'
import { initAppProvides } from './export/inject'

const appHooksMap = makeMap(mergeLifecycle(LIFECYCLE).app)

Expand Down Expand Up @@ -47,11 +47,6 @@ export default function createApp (option, config = {}) {
}
global.__mpxEnterOptions = options
this.$options.onLaunch && this.$options.onLaunch.call(this, options)
global.__mpxAppCbs = global.__mpxAppCbs || {
show: [],
hide: [],
error: []
}
if (isBrowser) {
if (this.$options.onShow) {
this.$options.onShow.call(this, options)
Expand All @@ -63,6 +58,9 @@ export default function createApp (option, config = {}) {
if (this.$options.onError) {
global.__mpxAppCbs.error.push(this.$options.onError.bind(this))
}
if (this.$options.onUnhandledRejection) {
global.__mpxAppCbs.rejection.push(this.$options.onUnhandledRejection.bind(this))
}
}
}
})
Expand Down
Loading

0 comments on commit 2eb1a86

Please sign in to comment.