How to use the @tarojs/taro.Current.current function in @tarojs/taro

To help you get started, we’ve selected a few @tarojs/taro examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NervJS / taro / packages / taro-alipay / src / lifecycle.js View on Github external
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')
    }
  }
github NervJS / taro / packages / taro-quickapp / src / create-component.js View on Github external
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)) {
github NervJS / taro / packages / taro-qq / src / create-component.js View on Github external
} 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
github NervJS / taro / packages / taro-jd / src / util.js View on Github external
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]
  }
}
github NervJS / taro / packages / taro-quickapp / src / lifecycle.js View on Github external
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)
    }
  }
}
github NervJS / taro / packages / taro-weapp / src / util.js View on Github external
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]
  }
}
github NervJS / taro / packages / taro-tt / src / create-component.js View on Github external
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({
github NervJS / taro / packages / taro-swan / src / util.js View on Github external
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]
  }
}
github NervJS / taro / packages / taro-swan / src / lifecycle.js View on Github external
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) {