diff --git a/packages/core/src/convertor/convertor.js b/packages/core/src/convertor/convertor.js
index 6139f4a194..0efbac8e0e 100644
--- a/packages/core/src/convertor/convertor.js
+++ b/packages/core/src/convertor/convertor.js
@@ -1,6 +1,6 @@
import { LIFECYCLE, lifecycleProxyMap, pageMode } from '../platform/patch/lifecycle/index'
import { mergeLifecycle } from './mergeLifecycle'
-import { error } from '@mpxjs/utils'
+import { error, extend } from '@mpxjs/utils'
import wxToAliRule from './wxToAli'
import wxToWebRule from './wxToWeb'
import wxToSwanRule from './wxToSwan'
@@ -27,17 +27,17 @@ const defaultConvertRule = {
}
const rulesMap = {
- local: { ...defaultConvertRule },
+ local: extend({}, defaultConvertRule),
default: defaultConvertRule,
wxToWeb: wxToWebRule,
wxToAli: wxToAliRule,
wxToSwan: wxToSwanRule,
- wxToQq: { ...defaultConvertRule, ...wxToQqRule },
- wxToTt: { ...defaultConvertRule, ...wxToTtRule },
- wxToDd: { ...defaultConvertRule, ...wxToDdRule },
- wxToJd: { ...defaultConvertRule, ...wxToJdRule },
- wxToIos: { ...defaultConvertRule, ...wxToReactRule },
- wxToAndroid: { ...defaultConvertRule, ...wxToReactRule }
+ wxToQq: extend({}, defaultConvertRule, wxToQqRule),
+ wxToTt: extend({}, defaultConvertRule, wxToTtRule),
+ wxToDd: extend({}, defaultConvertRule, wxToDdRule),
+ wxToJd: extend({}, defaultConvertRule, wxToJdRule),
+ wxToIos: extend({}, defaultConvertRule, wxToReactRule),
+ wxToAndroid: extend({}, defaultConvertRule, wxToReactRule)
}
export function getConvertRule (convertMode) {
diff --git a/packages/core/src/observer/ref.js b/packages/core/src/observer/ref.js
index 1f1bce28aa..1fa93a5b91 100644
--- a/packages/core/src/observer/ref.js
+++ b/packages/core/src/observer/ref.js
@@ -3,12 +3,13 @@ import { RefKey } from '../helper/const'
import {
warn,
isPlainObject,
- hasOwn
+ hasOwn,
+ extend
} from '@mpxjs/utils'
export class RefImpl {
constructor (options) {
- Object.defineProperty(this, 'value', { enumerable: true, ...options })
+ Object.defineProperty(this, 'value', extend({ enumerable: true }, options))
}
}
diff --git a/packages/core/src/observer/watch.js b/packages/core/src/observer/watch.js
index 7a8cbd4ef2..0c6095a083 100644
--- a/packages/core/src/observer/watch.js
+++ b/packages/core/src/observer/watch.js
@@ -12,7 +12,8 @@ import {
isArray,
remove,
callWithErrorHandling,
- hasChanged
+ hasChanged,
+ extend
} from '@mpxjs/utils'
export function watchEffect (effect, options) {
@@ -20,11 +21,11 @@ export function watchEffect (effect, options) {
}
export function watchPostEffect (effect, options) {
- return watch(effect, null, { ...options, flush: 'post' })
+ return watch(effect, null, extend({}, options, { flush: 'post' }))
}
export function watchSyncEffect (effect, options) {
- return watch(effect, null, { ...options, flush: 'sync' })
+ return watch(effect, null, extend({}, options, { flush: 'sync' }))
}
const warnInvalidSource = (s) => {
@@ -34,7 +35,7 @@ const warnInvalidSource = (s) => {
const shouldTrigger = (value, oldValue) => hasChanged(value, oldValue) || isObject(value)
const processWatchOptionsCompat = (options) => {
- const newOptions = { ...options }
+ const newOptions = extend({}, options)
if (options.sync) {
newOptions.flush = 'sync'
}
diff --git a/packages/core/src/platform/createApp.ios.js b/packages/core/src/platform/createApp.ios.js
index 2d7c939e7a..5cd4dc9aee 100644
--- a/packages/core/src/platform/createApp.ios.js
+++ b/packages/core/src/platform/createApp.ios.js
@@ -1,6 +1,6 @@
import transferOptions from '../core/transferOptions'
import builtInKeysMap from './patch/builtInKeysMap'
-import { makeMap, spreadProp, parseUrlQuery, getFocusedNavigation, hasOwn } from '@mpxjs/utils'
+import { makeMap, spreadProp, parseUrlQuery, getFocusedNavigation, hasOwn, extend } from '@mpxjs/utils'
import { mergeLifecycle } from '../convertor/mergeLifecycle'
import { LIFECYCLE } from '../platform/patch/lifecycle/index'
import Mpx from '../index'
@@ -30,11 +30,7 @@ function filterOptions (options, appData) {
}
function createAppInstance (appData) {
- const instance = {
- ...Mpx.prototype,
- ...appData
- }
- return instance
+ return extend({}, Mpx.prototype, appData)
}
export default function createApp (option, config = {}) {
diff --git a/packages/fetch/src/index.js b/packages/fetch/src/index.js
index 132f752348..2d56ceaed7 100644
--- a/packages/fetch/src/index.js
+++ b/packages/fetch/src/index.js
@@ -1,5 +1,6 @@
import XFetch from './xfetch'
import CancelToken from './cancelToken'
+import { extend } from '@mpxjs/utils'
let installed = false
@@ -15,7 +16,7 @@ function install (proxyMpx, options, Mpx) {
if (installed) return
// add request queue when mode is qq
const isqq = __mpx_mode__ === 'qq'
- xfetch = new XFetch(isqq ? { useQueue: defaultRequestQueueOptions, ...options } : options, Mpx)
+ xfetch = new XFetch(isqq ? extend({ useQueue: defaultRequestQueueOptions }, options) : options, Mpx)
installed = true
proxyMpx.xfetch = xfetch
Object.defineProperty(proxyMpx.prototype, '$xfetch', {
diff --git a/packages/fetch/src/util.js b/packages/fetch/src/util.js
index e3ff45c87f..df086cc83b 100644
--- a/packages/fetch/src/util.js
+++ b/packages/fetch/src/util.js
@@ -1,7 +1,5 @@
import { match } from 'path-to-regexp'
-
-import { type, isFunction, isArray, isString, forEach, isNumber } from '@mpxjs/utils/src/base'
-import { serialize, buildUrl, parseUrl } from '@mpxjs/utils/src/url'
+import { type, isFunction, isArray, isString, forEach, isNumber, serialize, buildUrl, parseUrl, extend } from '@mpxjs/utils'
const toString = Object.prototype.toString
const hasOwnProperty = Object.prototype.hasOwnProperty
@@ -212,7 +210,7 @@ function checkCacheConfig (thisConfig, cacheData) {
paramsEquals = thisConfig.usePre.equals(thisConfig, cacheData)
} else {
paramsEquals = compareParams(thisConfig.params, cacheData.params, thisConfig.usePre.ignorePreParamKeys) &&
- compareParams(thisConfig.data, cacheData.data, thisConfig.usePre.ignorePreParamKeys)
+ compareParams(thisConfig.data, cacheData.data, thisConfig.usePre.ignorePreParamKeys)
}
return paramsEquals && thisConfig.method === cacheData.method
}
@@ -263,6 +261,7 @@ export {
isThenable,
isFunction,
isNumber,
+ extend,
parseUrl,
deepMerge,
doTest,
diff --git a/packages/fetch/src/xfetch.js b/packages/fetch/src/xfetch.js
index 0eb7b1de12..88a842fad2 100644
--- a/packages/fetch/src/xfetch.js
+++ b/packages/fetch/src/xfetch.js
@@ -4,7 +4,7 @@ import InterceptorManager from './interceptorManager'
import RequestQueue from './queue'
import { requestProxy } from './proxy'
import { Validator } from './validator'
-import { isNotEmptyArray, isNotEmptyObject, transformReq, isObject, formatCacheKey, checkCacheConfig, isArray, isString } from './util'
+import { isNotEmptyArray, isNotEmptyObject, transformReq, isObject, formatCacheKey, checkCacheConfig, isArray, isString, extend } from './util'
export default class XFetch {
constructor (options, MPX) {
@@ -13,10 +13,9 @@ export default class XFetch {
// this.requestAdapter = (config) => requestAdapter(config, MPX)
// 当存在 useQueue 配置时,才使用 this.queue 变量
if (options && options.useQueue && typeof options.useQueue === 'object') {
- this.queue = new RequestQueue({
- adapter: (config) => requestAdapter(config, MPX),
- ...options.useQueue
- })
+ this.queue = new RequestQueue(extend({
+ adapter: (config) => requestAdapter(config, MPX)
+ }, options.useQueue))
} else {
this.requestAdapter = (config) => requestAdapter(config, MPX)
}
@@ -177,7 +176,7 @@ export default class XFetch {
if (isNotExpired && checkCacheConfig(config, cacheRequestData) && cacheRequestData.responsePromise) {
return cacheRequestData.responsePromise.then(response => {
// 添加 isCache 标识该请求来源于缓存
- return { ...response, isCache: true }
+ return extend(response, { isCache: true })
})
} else {
delete this.cacheRequestData[cacheKey]
diff --git a/packages/utils/src/object.js b/packages/utils/src/object.js
index bd05a66459..9ac08cb1f3 100644
--- a/packages/utils/src/object.js
+++ b/packages/utils/src/object.js
@@ -2,6 +2,8 @@ import { type, noop, isObject } from './base'
const hasOwnProperty = Object.prototype.hasOwnProperty
+const extend = Object.assign
+
function hasOwn (obj, key) {
return isObject(obj) && hasOwnProperty.call(obj, key)
}
@@ -189,6 +191,7 @@ function processUndefined (obj) {
export {
hasOwn,
+ extend,
isPlainObject,
diffAndCloneA,
proxy,
diff --git a/packages/webpack-plugin/lib/runtime/components/web/getInnerListeners.js b/packages/webpack-plugin/lib/runtime/components/web/getInnerListeners.js
index 2facddbb94..dfaedfa8c9 100644
--- a/packages/webpack-plugin/lib/runtime/components/web/getInnerListeners.js
+++ b/packages/webpack-plugin/lib/runtime/components/web/getInnerListeners.js
@@ -1,3 +1,4 @@
+import { extend } from '../../utils'
function processModel (listeners, context) {
// 该函数只有wx:model的情况下才调用,而且默认e.detail.value有值
// 该函数必须在产生merge前执行
@@ -53,7 +54,7 @@ export function extendEvent (e, extendObj = {}) {
}
export function inheritEvent (type, oe, detail = {}) {
- detail = Object.assign({}, oe.detail, detail)
+ detail = extend({}, oe.detail, detail)
const ne = getCustomEvent(type, detail)
extendEvent(ne, {
timeStamp: oe.timeStamp,
@@ -68,12 +69,11 @@ export function inheritEvent (type, oe, detail = {}) {
export function getCustomEvent (type, detail = {}, target = null) {
const targetEl = (target && target.$el) || null
const targetInfo = targetEl ? { target: targetEl, currentTarget: targetEl } : {}
- return {
+ return extend({
type,
detail,
- timeStamp: new Date().valueOf(),
- ...targetInfo
- }
+ timeStamp: new Date().valueOf()
+ }, targetInfo)
}
function noop () {
@@ -82,7 +82,7 @@ function noop () {
export default function getInnerListeners (context, options = {}) {
let { mergeBefore = {}, mergeAfter = {}, defaultListeners = [], ignoredListeners = [] } = options
- const listeners = Object.assign({}, context.$listeners)
+ const listeners = extend({}, context.$listeners)
defaultListeners.forEach((key) => {
if (!listeners[key]) listeners[key] = noop
})
diff --git a/packages/webpack-plugin/lib/runtime/components/web/mpx-movable-view.vue b/packages/webpack-plugin/lib/runtime/components/web/mpx-movable-view.vue
index 620c4e1413..167fc531c1 100644
--- a/packages/webpack-plugin/lib/runtime/components/web/mpx-movable-view.vue
+++ b/packages/webpack-plugin/lib/runtime/components/web/mpx-movable-view.vue
@@ -7,379 +7,369 @@
diff --git a/packages/webpack-plugin/lib/runtime/optionProcessor.js b/packages/webpack-plugin/lib/runtime/optionProcessor.js
index 3186ef38df..b1949f04cc 100644
--- a/packages/webpack-plugin/lib/runtime/optionProcessor.js
+++ b/packages/webpack-plugin/lib/runtime/optionProcessor.js
@@ -1,4 +1,4 @@
-import { hasOwn, isEmptyObject } from './utils'
+import { hasOwn, isEmptyObject, extend } from './utils'
import { isBrowser } from './env'
import transRpxStyle from './transRpxStyle'
import animation from './animation'
@@ -59,7 +59,7 @@ registered in parent context!`)
}
if (ctorType === 'page') {
- option.__mpxPageConfig = Object.assign({}, global.__mpxPageConfig, pageConfig)
+ option.__mpxPageConfig = extend({}, global.__mpxPageConfig, pageConfig)
}
if (!hasApp) {
@@ -109,7 +109,7 @@ registered in parent context!`)
export function getComponent (component, extendOptions) {
component = component.__esModule ? component.default : component
// eslint-disable-next-line
- if (extendOptions) Object.assign(component, extendOptions)
+ if (extendOptions) extend(component, extendOptions)
return component
}
@@ -164,10 +164,7 @@ function createApp ({ componentsMap, Vue, pagesMap, firstPage, VueRouter, App, t
})
}
const webRouteConfig = global.__mpx.config.webConfig.routeConfig || global.__mpx.config.webRouteConfig
- global.__mpxRouter = option.router = new VueRouter({
- ...webRouteConfig,
- routes: routes
- })
+ global.__mpxRouter = option.router = new VueRouter(extend({ routes }, webRouteConfig))
let mpxStackPath = []
if (isBrowser) {
// 解决webview被刷新导致路由栈丢失后产生错乱问题
@@ -365,7 +362,7 @@ function createApp ({ componentsMap, Vue, pagesMap, firstPage, VueRouter, App, t
if (App.onAppInit) {
global.__mpxAppInit = true
- Object.assign(option, App.onAppInit() || {})
+ extend(option, App.onAppInit() || {})
global.__mpxAppInit = false
}
@@ -374,14 +371,8 @@ function createApp ({ componentsMap, Vue, pagesMap, firstPage, VueRouter, App, t
option.pinia = global.__mpxPinia
}
- const app = new Vue({
- ...option,
- render: (h) => h(App)
- })
- return {
- app,
- ...option
- }
+ const app = new Vue(extend(option, { render: (h) => h(App) }))
+ return extend({ app }, option)
}
export function processAppOption ({ firstPage, pagesMap, componentsMap, App, Vue, VueRouter, tabBarMap, el }) {
diff --git a/packages/webpack-plugin/lib/runtime/utils.js b/packages/webpack-plugin/lib/runtime/utils.js
index ab77f13bdf..fccb46f6ed 100644
--- a/packages/webpack-plugin/lib/runtime/utils.js
+++ b/packages/webpack-plugin/lib/runtime/utils.js
@@ -45,3 +45,5 @@ const hasOwnProperty = Object.prototype.hasOwnProperty
export function hasOwn (obj, key) {
return hasOwnProperty.call(obj, key)
}
+
+export const extend = Object.assign
diff --git a/packages/webview-bridge/src/index.js b/packages/webview-bridge/src/index.js
index a3b9fd6ce6..4954ef0478 100644
--- a/packages/webview-bridge/src/index.js
+++ b/packages/webview-bridge/src/index.js
@@ -1,6 +1,6 @@
import loadScript from './loadscript'
let sdkReady
-const SDK_URL_MAP = {
+const SDK_URL_MAP = Object.assign({
wx: {
url: 'https://res.wx.qq.com/open/js/jweixin-1.3.2.js'
},
@@ -15,9 +15,8 @@ const SDK_URL_MAP = {
},
tt: {
url: 'https://lf3-cdn-tos.bytegoofy.com/obj/goofy/developer/jssdk/jssdk-1.2.1.js'
- },
- ...window.sdkUrlMap
-}
+ }
+}, window.sdkUrlMap)
function getMpxWebViewId () {
const href = location.href
const reg = /mpx_webview_id=(\d+)/g