Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
component._createData(component.state, component.props, true)
component._disableEffect = false
Current.current = null
}
if (typeof component.componentDidUpdate === 'function') {
component.componentDidUpdate(prevProps, prevState, snapshot)
}
} else if (component.$componentType === 'PAGE' && component['$$hasLoopRef']) {
// 解决初始化时 onLoad 最先触发,但拿不到子组件 ref 的问题
Current.current = component
Current.index = 0
component._disableEffect = true
component._createData(component.state, component.props, true)
component._disableEffect = false
Current.current = null
}
if (cbs.length) {
let i = cbs.length
while (--i >= 0) {
typeof cbs[i] === 'function' && cbs[i].call(component)
}
}
if (!component.__mounted) {
component.__mounted = true
componentTrigger(component, 'componentDidMount')
componentTrigger(component, 'componentDidShow')
}
}
export default function createComponent (ComponentClass, isPage) {
let initData = {}
const componentProps = filterProps(ComponentClass.defaultProps)
const componentInstance = new ComponentClass(componentProps)
componentInstance._constructor && componentInstance._constructor(componentProps)
try {
Current.current = componentInstance
Current.index = 0
componentInstance.state = componentInstance._createData() || componentInstance.state
} catch (err) {
if (isPage) {
console.warn(`[Taro warn] 请给页面提供初始 \`state\` 以提高初次渲染性能!`)
} else {
console.warn(`[Taro warn] 请给组件提供一个 \`defaultProps\` 以提高初次渲染性能!`)
}
console.warn(err)
}
initData = Object.assign({}, initData, componentInstance.props, componentInstance.state)
const componentConf = {
data: initData,
onInit () {
isPage && (hasPageInited = false)
if (isPage && cacheDataHas(preloadInitedComponent)) {
} else {
const query = qq.createSelectorQuery().in(component.$scope)
target = query.select(`#${ref.id}`)
}
commitAttachRef(ref, target, component, refs, true)
ref.target = target
})
component.refs = Object.assign({}, component.refs || {}, refs)
}
if (component['$$hasLoopRef']) {
Current.current = component
Current.index = 0
component._disableEffect = true
component._createData(component.state, component.props, true)
component._disableEffect = false
Current.current = null
}
}
if (key === 'componentWillUnmount') {
const compid = component.$scope.data.compid
if (compid) propsManager.delete(compid)
}
component[key] && typeof component[key] === 'function' && component[key].call(component, ...args)
if (key === 'componentWillMount') {
component._dirty = false
component._disable = false
component.state = component.getState()
}
if (key === 'componentWillUnmount') {
component._dirty = true
export function genCompid (key, isNeedCreate) {
if (!Current || !Current.current || !Current.current.$scope) return []
const prevId = compIdsMapper.get(key)
if (isNeedCreate) {
const id = genId()
compIdsMapper.set(key, id)
return [prevId, id]
} else {
const id = prevId || genId()
!prevId && compIdsMapper.set(key, id)
return [null, id]
}
}
if (!(item in component.$scope)) {
component.$scope.$set(item, data[item])
} else {
component.$scope[item] = data[item]
}
})
if (__mounted) {
invokeEffects(component)
if (component['$$hasLoopRef']) {
Current.current = component
Current.index = 0
component._disableEffect = true
component._createData(component.state, component.props, true)
component._disableEffect = false
Current.current = null
}
if (isFunction(component.componentDidUpdate)) {
component.componentDidUpdate(prevProps, prevState, snapshot)
}
}
if (cbs.length) {
let i = cbs.length
while (--i >= 0) {
isFunction(cbs[i]) && cbs[i].call(component)
}
}
}
export function genCompid (key, isNeedCreate) {
if (!Current || !Current.current || !Current.current.$scope) return []
const prevId = compIdsMapper.get(key)
if (isNeedCreate) {
const id = genId()
compIdsMapper.set(key, id)
return [prevId, id]
} else {
const id = prevId || genId()
!prevId && compIdsMapper.set(key, id)
return [null, id]
}
}
export function componentTrigger (component, key, args) {
args = args || []
if (key === 'componentDidMount') {
if (component['$$hasLoopRef']) {
Current.current = component
Current.index = 0
component._disableEffect = true
component._createData(component.state, component.props, true)
component._disableEffect = false
Current.current = null
}
if (component['$$refs'] && component['$$refs'].length > 0) {
let refs = {}
const refComponents = []
component['$$refs'].forEach(ref => {
refComponents.push(new Promise((resolve, reject) => {
const query = tt.createSelectorQuery().in(component.$scope)
if (ref.type === 'component') {
component.$scope.selectComponent(`#${ref.id}`, target => {
resolve({
export function genCompid (key, isNeedCreate) {
if (!Current || !Current.current || !Current.current.$scope) return []
const prevId = compIdsMapper.get(key)
if (isNeedCreate) {
const id = genId()
compIdsMapper.set(key, id)
return [prevId, id]
} else {
const id = prevId || genId()
!prevId && compIdsMapper.set(key, id)
return [null, id]
}
}
const prevRef = ref.target
if (target !== prevRef) {
commitAttachRef(ref, target, component, component.refs)
ref.target = target
}
})
}
if (component['$$hasLoopRef']) {
Current.current = component
Current.index = 0
component._disableEffect = true
component._createData(component.state, component.props, true)
component._disableEffect = false
Current.current = null
}
if (typeof component.componentDidUpdate === 'function') {
component.componentDidUpdate(prevProps, prevState, snapshot)
}
}
if (cbs.length) {
let i = cbs.length
while (--i >= 0) {
typeof cbs[i] === 'function' && cbs[i].call(component)
}
}
}
if (Object.keys(dataDiff).length === 0) {