Skip to content

Commit

Permalink
feat(runtime-mini): 事件参数解析配合改造
Browse files Browse the repository at this point in the history
  • Loading branch information
hwaphon committed Apr 28, 2024
1 parent 4e1e29c commit 2c3097f
Showing 1 changed file with 4 additions and 21 deletions.
25 changes: 4 additions & 21 deletions packages/runtime-mini/src/alipay/componentToOther.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import {
compose,
generateId,
getSharedProperty,
logger
logger,
Pairs
} from '@morjs/runtime-base'
import clone from 'clone-deep'
import { injectHasMixinSupport } from '../common/behaviorOrMixin'
Expand Down Expand Up @@ -111,24 +112,6 @@ function cloneDeep<T = Record<string, any>>(
}
}

/**
* 根据键值对字符串创建对象
* @param {string} param - 以短横线分隔的键值对字符串,形如 "key1_value1-key2_value2"
* @returns {Object} - 创建的对象,键为原始字符串中的 key,值为对应的 value
*/
function getObjectFromPairs(param) {
const result = {}
if (typeof param !== 'string') return result

const paramsArr = param.split('-')
paramsArr.forEach((pair) => {
const [key, value] = pair.split('_')
result[key] = value
})

return result
}

/**
* 生成随机不重复事件 ID
* @returns 事件 ID
Expand Down Expand Up @@ -516,7 +499,7 @@ function hookComponentLifeCycle(
}

// 触发小程序原生事件
// 事件会被 $morEventHandlerProxy 事件代理方法捕获
// 事件会被 $morEHP 事件代理方法捕获
// 并触发 event 事件, 基于 eventId
this.triggerEvent(triggerEventName, {
name: this[MOR_EVENT_HANDLERS][triggerEventName],
Expand All @@ -536,7 +519,7 @@ function hookComponentLifeCycle(
const morEventHandlers = this.dataset?.[MOR_EVENT_HANDLERS_DATASET]
if (morEventHandlers) {
try {
this[MOR_EVENT_HANDLERS] = getObjectFromPairs(morEventHandlers)
this[MOR_EVENT_HANDLERS] = Pairs.toObject(morEventHandlers)

// ref 支持
if (this[MOR_EVENT_HANDLERS].ref) {
Expand Down

0 comments on commit 2c3097f

Please sign in to comment.