diff --git a/docs-vitepress/api/optional-api.md b/docs-vitepress/api/optional-api.md index 6a67628ea..e69c6b145 100644 --- a/docs-vitepress/api/optional-api.md +++ b/docs-vitepress/api/optional-api.md @@ -1,5 +1,57 @@ # 选项式 API +### options.shallowReactivePattern +- **类型:** `RegExp` +- **详细:** + +取消data/properties内数据的深度响应。 + +适用于每次更新均为整体的更新而非局部少量数据更新的大型数据,可减少掉对应属性“数据响应初始化”以及“diff比较”两个阶段的耗时 + +```html + + + + + + +``` + +> 注意 + ### onAppInit - **类型:** `Function` - **详细:** diff --git a/packages/core/src/platform/env/index.ios.js b/packages/core/src/platform/env/index.ios.js index f18fcbcf4..971121dd8 100644 --- a/packages/core/src/platform/env/index.ios.js +++ b/packages/core/src/platform/env/index.ios.js @@ -1,3 +1,4 @@ +import { isFunction, isNumber, isString } from '@mpxjs/utils' import { createI18n } from '../builtInMixins/i18nMixin' export function init (Mpx) { @@ -30,21 +31,30 @@ 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) || isString(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 }) } } - if (global?.HermesInternal?.hasPromise?.()) { - global.HermesInternal?.enablePromiseRejectionTracker?.(rejectionTrackingOptions) + // 支持 core-js promise polyfill + const oldOnUnhandledRejection = global.onunhandledrejection + global.onunhandledrejection = function onunhandledrejection (event) { + onUnhandledRejection(event) + isFunction(oldOnUnhandledRejection) && oldOnUnhandledRejection.call(this, event) + } + if (global.HermesInternal?.hasPromise?.()) { + global.HermesInternal.enablePromiseRejectionTracker?.(rejectionTrackingOptions) } else { require('promise/setimmediate/rejection-tracking').enable(rejectionTrackingOptions) } diff --git a/packages/core/src/platform/env/index.web.js b/packages/core/src/platform/env/index.web.js index 58dccf2d0..39794f020 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`)