Skip to content

Commit

Permalink
fix(taro-alipay): 支付宝 ref 逻辑更新
Browse files Browse the repository at this point in the history
  • Loading branch information
Chen-jj committed Jan 16, 2019
1 parent 876d10c commit 3bfb315
Showing 1 changed file with 13 additions and 39 deletions.
52 changes: 13 additions & 39 deletions packages/taro-alipay/src/create-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,63 +165,30 @@ function filterProps (defaultProps = {}, componentProps = {}, weappComponentData

export function componentTrigger (component, key, args) {
args = args || []
if (key === 'componentWillMount') {
if (component['$$refs'] && component['$$refs'].length > 0) {
let refs = {}
component['$$refs'].forEach(ref => {
let target
if (ref.type === 'component') {
target = component.$scope.selectComponent(`#${ref.id}`)
target = target.$component || target
if ('refName' in ref && ref['refName']) {
refs[ref.refName] = target
} else if ('fn' in ref && typeof ref['fn'] === 'function') {
ref['fn'].call(component, target)
}
}
})
component.refs = Object.assign({}, component.refs || {}, refs)
}
}
if (key === 'componentDidMount') {
if (component['$$refs'] && component['$$refs'].length > 0) {
let refs = {}
component['$$refs'].forEach(ref => {
let target
const query = my.createSelectorQuery().in(component.$scope)
if (ref.type === 'dom') {
target = query.select(`#${ref.id}`)
if ('refName' in ref && ref['refName']) {
refs[ref.refName] = target
} else if ('fn' in ref && typeof ref['fn'] === 'function') {
ref['fn'].call(component, target)
}
}
})
component.refs = Object.assign({}, component.refs || {}, refs)
}
}

if (key === 'componentDidMount') {
if (component['$$refs'] && component['$$refs'].length > 0) {
let refs = {}
component['$$refs'].forEach(ref => {
let target
const query = my.createSelectorQuery().in(component.$scope)
if (ref.type === 'component') {
target = component.$scope.selectComponent(`#${ref.id}`)
target = target.$component || target
target = target ? (target.$component || target) : null
} else {
const query = wx.createSelectorQuery().in(component.$scope)
target = query.select(`#${ref.id}`)
}
if ('refName' in ref && ref['refName']) {
refs[ref.refName] = target
} else if ('fn' in ref && typeof ref['fn'] === 'function') {
ref['fn'].call(component, target)
}
ref.target = target
})
component.refs = refs
component.refs = Object.assign({}, component.refs || {}, refs)
}
}

if (key === 'componentWillUnmount') {
component._dirty = true
component._disable = true
Expand All @@ -238,6 +205,13 @@ export function componentTrigger (component, key, args) {
component._disable = false
component.state = component.getState()
}
if (key === 'componentWillUnmount') {
// refs
if (component['$$refs'] && component['$$refs'].length > 0) {
component['$$refs'].forEach(ref => typeof ref['fn'] === 'function' && ref['fn'].call(component, null))
component.refs = {}
}
}
}

let hasPageInited = false
Expand Down

0 comments on commit 3bfb315

Please sign in to comment.