How to use the @tarojs/taro.invokeEffects 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-quickapp / src / lifecycle.js View on Github external
function doUpdate (component, prevProps, prevState) {
  const { state, props = {} } = component
  let data = state || {}
  if (component._createData) {
    // 返回null或undefined则保持不变
    if (component.__isReady) {
      injectContextType(component)
      Current.current = component
      Current.index = 0
      invokeEffects(component, true)
    }
    data = component._createData(state, props) || data
    if (component.__isReady) {
      Current.current = null
    }
  }

  data = Object.assign({}, props, data)
  if (component.$usedState && component.$usedState.length) {
    const _data = {}
    component.$usedState.forEach(key => {
      let val = safeGet(data, key)
      if (typeof val === 'undefined') {
        return
      }
      if (typeof val === 'object') {
github NervJS / taro / packages / taro-weapp / src / lifecycle.js View on Github external
function doUpdate (component, prevProps, prevState) {
  const { state, props = {} } = component
  let data = state || {}
  if (component._createData) {
    if (component.__isReady) {
      injectContextType(component)
      Current.current = component
      Current.index = 0
      invokeEffects(component, true)
    }
    data = component._createData(state, props) || data
    if (component.__isReady) {
      Current.current = null
    }
  }

  data = Object.assign({}, props, data)
  if (component.$usedState && component.$usedState.length) {
    const _data = {}
    component.$usedState.forEach(key => {
      let val = safeGet(data, key)
      if (typeof val === 'undefined') {
        return
      }
      if (typeof val === 'object') {
github NervJS / taro / packages / taro-jd / src / lifecycle.js View on Github external
function doUpdate (component, prevProps, prevState) {
  const { state, props = {} } = component
  let data = state || {}
  if (component._createData) {
    if (component.__isReady) {
      injectContextType(component)
      Current.current = component
      Current.index = 0
      invokeEffects(component, true)
    }
    data = component._createData(state, props) || data
    if (component.__isReady) {
      Current.current = null
    }
  }

  data = Object.assign({}, props, data)
  if (component.$usedState && component.$usedState.length) {
    const _data = {}
    component.$usedState.forEach(key => {
      let val = safeGet(data, key)
      if (typeof val === 'undefined') {
        return
      }
      if (typeof val === 'object') {
github NervJS / taro / packages / taro-swan / src / lifecycle.js View on Github external
function doUpdate (component, prevProps, prevState) {
  const { state, props = {} } = component
  let data = state || {}
  if (component._createData) {
    if (component.__isReady) {
      injectContextType(component)
      Current.current = component
      Current.index = 0
      invokeEffects(component, true)
    }
    data = component._createData(state, props) || data
    if (component.__isReady) {
      Current.current = null
    }
  }

  data = Object.assign({}, props, data)
  if (component.$usedState && component.$usedState.length) {
    const _data = {}
    component.$usedState.forEach(key => {
      let val = safeGet(data, key)
      if (typeof val === 'undefined') {
        return
      }
      if (typeof val === 'object') {
github NervJS / taro / packages / taro-quickapp / src / lifecycle.js View on Github external
let cbs = []
  if (component._pendingCallbacks && component._pendingCallbacks.length) {
    cbs = component._pendingCallbacks
    component._pendingCallbacks = []
  }

  Object.keys(data).map(item => {
    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) {
github NervJS / taro / packages / taro-qq / src / lifecycle.js View on Github external
function doUpdate (component, prevProps, prevState) {
  const { state, props = {} } = component
  let data = state || {}
  if (component._createData) {
    if (component.__isReady) {
      injectContextType(component)
      Current.current = component
      Current.index = 0
      invokeEffects(component, true)
    }
    data = component._createData(state, props) || data
    if (component.__isReady) {
      Current.current = null
    }
  }

  data = Object.assign({}, props, data)
  if (component.$usedState && component.$usedState.length) {
    const _data = {}
    component.$usedState.forEach(key => {
      let val = safeGet(data, key)
      if (typeof val === 'undefined') {
        return
      }
      if (typeof val === 'object') {
github NervJS / taro / packages / taro-alipay / src / lifecycle.js View on Github external
const cb = function () {
    if (component.__mounted) {
      invokeEffects(component)
      if (component['$$refs'] && component['$$refs'].length > 0) {
        component['$$refs'].forEach(ref => {
          if (ref.type !== 'component') return

          const childs = component.$childs || {}
          let target = childs[ref.id] || null
          const prevRef = ref.target

          if (target !== prevRef) {
            commitAttachRef(ref, target, component, component.refs)
            ref.target = target
          }
        })
      }

      if (component['$$hasLoopRef']) {