Skip to content

Commit

Permalink
fix(taro): 编译后wxml自定义属性调整
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyadam committed Apr 23, 2018
1 parent b53bdc5 commit 8ca7b82
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions packages/taro/src/create-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { isEmptyObject, getPrototypeChain } from './util'

const eventPreffix = '__event_'
const rootScopeKey = '__root_'
const componentPath = 'componentPath'
function initPage (weappPageConf, page) {
const scopeMap = {}
function processEvent (eventHandlerName, obj, page) {
Expand All @@ -17,20 +18,15 @@ function initPage (weappPageConf, page) {
Object.assign(event.currentTarget, event.detail)
}
const dataset = event.currentTarget.dataset
const theComponent = scopeMap[dataset['__component_path'] || rootScopeKey]
const theComponent = scopeMap[dataset[componentPath] || rootScopeKey]
let scope = theComponent
const bindArgs = {}
Object.keys(dataset).forEach(key => {
const newEventHandlerNameLower = newEventHandlerName.toLocaleLowerCase()
if (
key.indexOf(eventPreffix) >= 0 &&
key.indexOf(newEventHandlerNameLower) >= 0
) {
const argName = key.replace(
`${eventPreffix}${newEventHandlerNameLower}_`,
''
)

const keyLower = key.toLocaleLowerCase()
if (keyLower.indexOf('event') >= 0 &&
keyLower.indexOf(newEventHandlerNameLower) >= 0) {
const argName = keyLower.replace(`event${newEventHandlerNameLower}`, '')
bindArgs[argName] = dataset[key]
}
})
Expand All @@ -49,8 +45,8 @@ function initPage (weappPageConf, page) {
}
newHandler()
} else {
if (dataset['__component_path']) {
scope = scopeMap[dataset['__component_path'] || rootScopeKey]
if (dataset[componentPath]) {
scope = scopeMap[dataset[componentPath] || rootScopeKey]
}
theComponent[eventHandlerName].call(scope, event)
}
Expand Down

0 comments on commit 8ca7b82

Please sign in to comment.