From 98a60c64113539a347785f0ad39cd7c0e92189fb Mon Sep 17 00:00:00 2001 From: mackwang Date: Wed, 15 Jan 2025 16:59:13 +0800 Subject: [PATCH 1/5] =?UTF-8?q?doc:=20=E8=A1=A5=E5=85=85=E9=80=89=E9=A1=B9?= =?UTF-8?q?=E5=BC=8Fapi=20options.shallowReactivePattern=20=E6=96=87?= =?UTF-8?q?=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs-vuepress/api/optional-api.md | 52 +++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/docs-vuepress/api/optional-api.md b/docs-vuepress/api/optional-api.md index 6a67628eab..e69c6b145f 100644 --- a/docs-vuepress/api/optional-api.md +++ b/docs-vuepress/api/optional-api.md @@ -1,5 +1,57 @@ # 选项式 API +### options.shallowReactivePattern +- **类型:** `RegExp` +- **详细:** + +取消data/properties内数据的深度响应。 + +适用于每次更新均为整体的更新而非局部少量数据更新的大型数据,可减少掉对应属性“数据响应初始化”以及“diff比较”两个阶段的耗时 + +```html + + + + + + +``` + +> 注意 + ### onAppInit - **类型:** `Function` - **详细:** From 581523c8050c9e224aae74b20d63163f8e551b99 Mon Sep 17 00:00:00 2001 From: mackwang Date: Fri, 17 Jan 2025 15:23:30 +0800 Subject: [PATCH 2/5] =?UTF-8?q?feat:=20onUnhandledRejection=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81core-js=20promise=20polyfill?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/platform/env/index.ios.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/core/src/platform/env/index.ios.js b/packages/core/src/platform/env/index.ios.js index f18fcbcf4c..dcf86e3cb6 100644 --- a/packages/core/src/platform/env/index.ios.js +++ b/packages/core/src/platform/env/index.ios.js @@ -43,8 +43,15 @@ function initGlobalErrorHandling () { } } + // 支持 core-js promise polyfill + const oldOnUnhandledRejection = global.onunhandledrejection + global.onunhandledrejection = function onunhandledrejection (event) { + // event = { promise, reason } + rejectionTrackingOptions.onUnhandled(null, event.reason) + oldOnUnhandledRejection.apply(this, event) + } if (global?.HermesInternal?.hasPromise?.()) { - global.HermesInternal?.enablePromiseRejectionTracker?.(rejectionTrackingOptions) + global.HermesInternal.enablePromiseRejectionTracker?.(rejectionTrackingOptions) } else { require('promise/setimmediate/rejection-tracking').enable(rejectionTrackingOptions) } From 31280e75b42b9b40ef20ea42ab0103c4248bd881 Mon Sep 17 00:00:00 2001 From: mackwang Date: Fri, 17 Jan 2025 17:26:21 +0800 Subject: [PATCH 3/5] =?UTF-8?q?feat:=20onUnhandledRejection=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81core-js=20promise=20polyfill?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/platform/env/index.ios.js | 23 ++++++++++++--------- packages/core/src/platform/env/index.web.js | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/packages/core/src/platform/env/index.ios.js b/packages/core/src/platform/env/index.ios.js index dcf86e3cb6..af2b1c6281 100644 --- a/packages/core/src/platform/env/index.ios.js +++ b/packages/core/src/platform/env/index.ios.js @@ -1,3 +1,4 @@ +import { isNumber, isString } from '@mpxjs/utils' import { createI18n } from '../builtInMixins/i18nMixin' export function init (Mpx) { @@ -30,25 +31,27 @@ function initGlobalErrorHandling () { }) } + function onUnhandledRejection (event) { + if (global.__mpxAppCbs && global.__mpxAppCbs.rejection && global.__mpxAppCbs.rejection.length) { + global.__mpxAppCbs.rejection.forEach((cb) => { + cb(event) + }) + } else { + console.warn(`UNHANDLED PROMISE REJECTION ${isNumber(event.id) ? '(id:' + event.id + ')' : ''}: ${event.reason}\n`) + } + } const rejectionTrackingOptions = { allRejections: true, onUnhandled (id, error) { - if (global.__mpxAppCbs && global.__mpxAppCbs.rejection && global.__mpxAppCbs.rejection.length) { - global.__mpxAppCbs.rejection.forEach((cb) => { - cb(error, id) - }) - } else { - console.warn(`UNHANDLED PROMISE REJECTION (id: ${id}): ${error}\n`) - } + onUnhandledRejection({ id, reason: error, promise: null }) } } // 支持 core-js promise polyfill const oldOnUnhandledRejection = global.onunhandledrejection global.onunhandledrejection = function onunhandledrejection (event) { - // event = { promise, reason } - rejectionTrackingOptions.onUnhandled(null, event.reason) - oldOnUnhandledRejection.apply(this, event) + onUnhandledRejection(event) + oldOnUnhandledRejection.call(this, event) } if (global?.HermesInternal?.hasPromise?.()) { global.HermesInternal.enablePromiseRejectionTracker?.(rejectionTrackingOptions) diff --git a/packages/core/src/platform/env/index.web.js b/packages/core/src/platform/env/index.web.js index 58dccf2d03..39794f020e 100644 --- a/packages/core/src/platform/env/index.web.js +++ b/packages/core/src/platform/env/index.web.js @@ -38,7 +38,7 @@ function initGlobalErrorHandling () { window.addEventListener('unhandledrejection', (event) => { if (global.__mpxAppCbs && global.__mpxAppCbs.rejection && global.__mpxAppCbs.rejection.length) { global.__mpxAppCbs.rejection.forEach((cb) => { - cb(event.reason, event.promise) + cb(event) }) } else { console.warn(`UNHANDLED PROMISE REJECTION: ${event.reason}\n`) From dc25d111ae0b0a2cb19441f05a982eb76dcf1ae0 Mon Sep 17 00:00:00 2001 From: mackwang Date: Fri, 17 Jan 2025 17:47:08 +0800 Subject: [PATCH 4/5] =?UTF-8?q?feat:=20onUnhandledRejection=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81core-js=20promise=20polyfill?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/platform/env/index.ios.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/core/src/platform/env/index.ios.js b/packages/core/src/platform/env/index.ios.js index af2b1c6281..7ff89d5380 100644 --- a/packages/core/src/platform/env/index.ios.js +++ b/packages/core/src/platform/env/index.ios.js @@ -1,4 +1,4 @@ -import { isNumber, isString } from '@mpxjs/utils' +import { isFunction, isNumber } from '@mpxjs/utils' import { createI18n } from '../builtInMixins/i18nMixin' export function init (Mpx) { @@ -51,9 +51,9 @@ function initGlobalErrorHandling () { const oldOnUnhandledRejection = global.onunhandledrejection global.onunhandledrejection = function onunhandledrejection (event) { onUnhandledRejection(event) - oldOnUnhandledRejection.call(this, event) + isFunction(oldOnUnhandledRejection) && oldOnUnhandledRejection.call(this, event) } - if (global?.HermesInternal?.hasPromise?.()) { + if (global.HermesInternal?.hasPromise?.()) { global.HermesInternal.enablePromiseRejectionTracker?.(rejectionTrackingOptions) } else { require('promise/setimmediate/rejection-tracking').enable(rejectionTrackingOptions) From 56fe10dc112825c727ef8bf9f5e047babd008a5d Mon Sep 17 00:00:00 2001 From: mackwang Date: Fri, 17 Jan 2025 17:53:02 +0800 Subject: [PATCH 5/5] =?UTF-8?q?feat:=20onUnhandledRejection=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81core-js=20promise=20polyfill?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/platform/env/index.ios.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/src/platform/env/index.ios.js b/packages/core/src/platform/env/index.ios.js index 7ff89d5380..971121dd81 100644 --- a/packages/core/src/platform/env/index.ios.js +++ b/packages/core/src/platform/env/index.ios.js @@ -1,4 +1,4 @@ -import { isFunction, isNumber } from '@mpxjs/utils' +import { isFunction, isNumber, isString } from '@mpxjs/utils' import { createI18n } from '../builtInMixins/i18nMixin' export function init (Mpx) { @@ -37,7 +37,7 @@ function initGlobalErrorHandling () { cb(event) }) } else { - console.warn(`UNHANDLED PROMISE REJECTION ${isNumber(event.id) ? '(id:' + event.id + ')' : ''}: ${event.reason}\n`) + console.warn(`UNHANDLED PROMISE REJECTION ${(isNumber(event.id) || isString(event.id)) ? '(id:' + event.id + ')' : ''}: ${event.reason}\n`) } } const rejectionTrackingOptions = {