How to use @tarojs/utils - 10 common examples

To help you get started, we’ve selected a few @tarojs/utils 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 / create-component.js View on Github external
}

        // merge App router params
        const app = getApp()
        if (
          app.$router &&
          app.$router.params &&
          app.$router.params.query &&
          Object.keys(app.$router.params.query).length &&
          getCurrentPages().length === 1
        ) {
          Object.assign(this.$component.$router.params, options, app.$router.params.query)
        } else {
          Object.assign(this.$component.$router.params, options)
        }
        this.$component.$router.path = getCurrentPageUrl()

        // preload
        if (cacheDataHas(options[preloadPrivateKey])) {
          this.$component.$preloadData = cacheDataGet(options[preloadPrivateKey], true)
        } else {
          this.$component.$preloadData = null
        }

        initComponent.apply(this, [isPage])
      },
github NervJS / taro / packages / taro-qq / src / create-component.js View on Github external
this.$component.__isReady = true
  // 页面Ready的时候setData更新,此时并未didMount,触发observer但不会触发子组件更新
  // 小程序组件ready,但是数据并没有ready,需要通过updateComponent来初始化数据,setData完成之后才是真正意义上的组件ready
  // 动态组件执行改造函数副本的时,在初始化数据前计算好props
  if (!isPage) {
    const compid = this.data.compid
    if (compid) {
      propsManager.observers[compid] = {
        component: this.$component,
        ComponentClass
      }
    }
    const nextProps = filterProps(ComponentClass.defaultProps, propsManager.map[compid], this.$component.props)
    this.$component.props = nextProps
  } else {
    this.$component.$router.path = getCurrentPageUrl()
  }
  mountComponent(this.$component)
}
github NervJS / taro / packages / taro-jd / src / create-component.js View on Github external
this.$component.__isReady = true
  // 页面Ready的时候setData更新,此时并未didMount,触发observer但不会触发子组件更新
  // 小程序组件ready,但是数据并没有ready,需要通过updateComponent来初始化数据,setData完成之后才是真正意义上的组件ready
  // 动态组件执行改造函数副本的时,在初始化数据前计算好props
  if (!isPage) {
    const compid = this.data.compid
    if (compid) {
      propsManager.observers[compid] = {
        component: this.$component,
        ComponentClass
      }
    }
    const nextProps = filterProps(ComponentClass.defaultProps, propsManager.map[compid], this.$component.props, this.data.extraProps)
    this.$component.props = nextProps
  } else {
    this.$component.$router.path = getCurrentPageUrl()
  }
  mountComponent(this.$component)
}
github NervJS / taro / packages / taro-weapp / src / create-component.js View on Github external
this.$component.__isReady = true
  // 页面Ready的时候setData更新,此时并未didMount,触发observer但不会触发子组件更新
  // 小程序组件ready,但是数据并没有ready,需要通过updateComponent来初始化数据,setData完成之后才是真正意义上的组件ready
  // 动态组件执行改造函数副本的时,在初始化数据前计算好props
  if (!isPage) {
    const compid = this.data.compid
    if (compid) {
      propsManager.observers[compid] = {
        component: this.$component,
        ComponentClass
      }
    }
    const nextProps = filterProps(ComponentClass.defaultProps, propsManager.map[compid], this.$component.props, this.data.extraProps)
    this.$component.props = nextProps
  } else {
    this.$component.$router.path = getCurrentPageUrl()
  }
  mountComponent(this.$component)
}
github NervJS / taro / packages / taro-tt / src / create-component.js View on Github external
}
      this.$component._init(this)
      this.$component.render = this.$component._createData
      this.$component.__propTypes = ComponentClass.propTypes
      if (isPage) {
        if (cacheDataHas(PRELOAD_DATA_KEY)) {
          const data = cacheDataGet(PRELOAD_DATA_KEY, true)
          this.$component.$router.preload = data
        }
        Object.assign(this.$component.$router.params, options)
        if (cacheDataHas(options[preloadPrivateKey])) {
          this.$component.$preloadData = cacheDataGet(options[preloadPrivateKey], true)
        } else {
          this.$component.$preloadData = {}
        }
        this.$component.$router.path = getCurrentPageUrl()
        initComponent.apply(this, [ComponentClass, isPage])
      }
    },
    attached () {
github NervJS / taro / packages / taro-swan / src / create-component.js View on Github external
created (options = {}) {
      isPage && (hasPageInited = false)
      this.$component = new ComponentClass({}, isPage)
      this.$component._init(this)
      this.$component.render = this.$component._createData
      this.$component.__propTypes = ComponentClass.propTypes
      Object.assign(this.$component.$router.params, options)
      if (isPage) {
        if (cacheDataHas(PRELOAD_DATA_KEY)) {
          const data = cacheDataGet(PRELOAD_DATA_KEY, true)
          this.$component.$router.preload = data
        }
        this.$component.$router.path = getCurrentPageUrl()
        initComponent.apply(this, [ComponentClass, isPage])
      }
    },
    attached () {
github NervJS / taro / packages / taro-quickapp / src / util.js View on Github external
const key = keys[i]
    if (i === len - 1) return obj[key]
    obj = obj[key]
  }
}

let id = 0
function genId () {
  return String(id++)
}

let compIdsMapper
try {
  compIdsMapper = new Map()
} catch (error) {
  compIdsMapper = new SimpleMap()
}
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-alipay / src / util.js View on Github external
if (res) return res

  return null
}

let id = 0
function genId () {
  return String(id++)
}

let compIdsMapper
try {
  compIdsMapper = new Map()
} catch (error) {
  compIdsMapper = new SimpleMap()
}
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-jd / src / util.js View on Github external
if (res) return res

  return null
}

let id = 0
function genId () {
  return String(id++)
}

let compIdsMapper
try {
  compIdsMapper = new Map()
} catch (error) {
  compIdsMapper = new SimpleMap()
}
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-qq / src / util.js View on Github external
if (res) return res

  return null
}

let id = 0
function genId () {
  return String(id++)
}

let compIdsMapper
try {
  compIdsMapper = new Map()
} catch (error) {
  compIdsMapper = new SimpleMap()
}
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]
  }
}

@tarojs/utils

Utils for Taro

MIT
Latest version published 4 years ago

Package Health Score

70 / 100
Full package analysis