How to use the @tarojs/shared.Shortcuts.Childnodes function in @tarojs/shared

To help you get started, we’ve selected a few @tarojs/shared 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-runtime / src / dom / root.ts View on Github external
setTimeout(() => {
      const data: Record> = Object.create(null)
      const resetPaths = new Set(
        initRender
          ? ['root.cn.[0]', 'root.cn[0]']
          : []
      )

      while (this.updatePayloads.length > 0) {
        const { path, value } = this.updatePayloads.shift()!
        if (path.endsWith(Shortcuts.Childnodes)) {
          resetPaths.add(path)
        }
        data[path] = value
      }

      for (const path in data) {
        resetPaths.forEach(p => {
          // 已经重置了数组,就不需要分别再设置了
          if (path.includes(p) && path !== p) {
            delete data[path]
          }
        })

        const value = data[path]
        if (isFunction(value)) {
          data[path] = value()
github NervJS / taro / packages / taro-runtime / src / render.ts View on Github external
export function hydrate (node: TaroElement | TaroText): MiniData {
  if (isText(node)) {
    return {
      [Shortcuts.Text]: node.nodeValue,
      [Shortcuts.NodeName]: node.nodeName
    }
  }

  const data: MiniData = {
    ...node.props,
    [Shortcuts.Childnodes]: node.childNodes.map(hydrate),
    [Shortcuts.NodeName]: node.nodeName,
    uid: node.uid
  }

  if (node.className) {
    data[Shortcuts.Class] = node.className
  }

  if (node.cssText) {
    data[Shortcuts.Style] = node.cssText
  }

  // eslint-disable-next-line dot-notation
  delete data['class']
  // eslint-disable-next-line dot-notation
  delete data['style']
github NervJS / taro / packages / taro-mini-runner / src / template / index.ts View on Github external
function buildThirdPartyTemplate (level: number, supportRecursive: boolean) {
  const nextLevel = supportRecursive ? 0 : level + 1
  let template = ''

  for (const [compName, attrs] of componentConfig.thirdPartyComponents) {
    template += `
<template name="tmpl_${level}_${compName}">
  &lt;${compName} ${buildThirdPartyAttr(attrs)} id="{{ i.uid }}"&gt;
    
      <template is="">
    
  
</template>
`
  }

  return template
}
</template>
github NervJS / taro / packages / taro-runtime / src / dom / node.ts View on Github external
public insertBefore (newChild: T, refChild?: TaroNode | null, isReplace?: boolean): T {
    newChild.remove()
    newChild.parentNode = this
    let payload: UpdatePayload
    if (refChild) {
      const index = this.findIndex(this.childNodes, refChild)
      this.childNodes.splice(index, 0, newChild)
      if (isReplace === true) {
        payload = {
          path: newChild._path,
          value: this.hydrate(newChild)
        }
      } else {
        payload = {
          path: `${this._path}.${Shortcuts.Childnodes}`,
          value: () =&gt; this.childNodes.map(hydrate)
        }
      }
    } else {
      this.childNodes.push(newChild)
      payload = {
        path: newChild._path,
        value: this.hydrate(newChild)
      }
    }

    this.enqueueUpdate(payload)
    return newChild
  }