Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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()
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']
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}">
<${compName} ${buildThirdPartyAttr(attrs)} id="{{ i.uid }}">
<template is="">
</template>
`
}
return template
}
</template>
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: () => this.childNodes.map(hydrate)
}
}
} else {
this.childNodes.push(newChild)
payload = {
path: newChild._path,
value: this.hydrate(newChild)
}
}
this.enqueueUpdate(payload)
return newChild
}