Skip to content

Commit

Permalink
rm object spread
Browse files Browse the repository at this point in the history
  • Loading branch information
hiyuki committed Dec 10, 2024
1 parent cff64ba commit e59740f
Show file tree
Hide file tree
Showing 16 changed files with 1,002 additions and 1,023 deletions.
16 changes: 8 additions & 8 deletions packages/core/src/convertor/convertor.js
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/observer/ref.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
9 changes: 5 additions & 4 deletions packages/core/src/observer/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@ import {
isArray,
remove,
callWithErrorHandling,
hasChanged
hasChanged,
extend
} from '@mpxjs/utils'

export function watchEffect (effect, options) {
return watch(effect, null, 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) => {
Expand All @@ -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'
}
Expand Down
8 changes: 2 additions & 6 deletions packages/core/src/platform/createApp.ios.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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 = {}) {
Expand Down
3 changes: 2 additions & 1 deletion packages/fetch/src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import XFetch from './xfetch'
import CancelToken from './cancelToken'
import { extend } from '@mpxjs/utils'

let installed = false

Expand All @@ -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', {
Expand Down
7 changes: 3 additions & 4 deletions packages/fetch/src/util.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -263,6 +261,7 @@ export {
isThenable,
isFunction,
isNumber,
extend,
parseUrl,
deepMerge,
doTest,
Expand Down
11 changes: 5 additions & 6 deletions packages/fetch/src/xfetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}
Expand Down Expand Up @@ -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]
Expand Down
3 changes: 3 additions & 0 deletions packages/utils/src/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -189,6 +191,7 @@ function processUndefined (obj) {

export {
hasOwn,
extend,
isPlainObject,
diffAndCloneA,
proxy,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { extend } from '../../utils'
function processModel (listeners, context) {
// 该函数只有wx:model的情况下才调用,而且默认e.detail.value有值
// 该函数必须在产生merge前执行
Expand Down Expand Up @@ -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,
Expand All @@ -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 () {
Expand All @@ -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
})
Expand Down
Loading

0 comments on commit e59740f

Please sign in to comment.