MCPcopy
hub / github.com/vuejs/core / insert

Function insert

packages/runtime-test/src/nodeOps.ts:140–171  ·  view source on GitHub ↗
(
  child: TestNode,
  parent: TestElement,
  ref?: TestNode | null,
)

Source from the content-addressed store, hash-verified

138}
139
140function insert(
141 child: TestNode,
142 parent: TestElement,
143 ref?: TestNode | null,
144): void {
145 let refIndex
146 if (ref) {
147 refIndex = parent.children.indexOf(ref)
148 if (refIndex === -1) {
149 console.error('ref: ', ref)
150 console.error('parent: ', parent)
151 throw new Error('ref is not a child of parent')
152 }
153 }
154 logNodeOp({
155 type: NodeOpTypes.INSERT,
156 targetNode: child,
157 parentNode: parent,
158 refNode: ref,
159 })
160 // remove the node first, but don't log it as a REMOVE op
161 remove(child, false)
162 // re-calculate the ref index because the child's removal may have affected it
163 refIndex = ref ? parent.children.indexOf(ref) : -1
164 if (refIndex === -1) {
165 parent.children.push(child)
166 child.parentNode = parent
167 } else {
168 parent.children.splice(refIndex, 0, child)
169 child.parentNode = parent
170 }
171}
172
173function remove(child: TestNode, logOp = true): void {
174 const parent = child.parentNode

Callers 6

hydrateNodeFunction · 0.85
hydrateChildrenFunction · 0.85
hydrateFragmentFunction · 0.85
processFunction · 0.85
moveTeleportFunction · 0.85
prepareAnchorFunction · 0.85

Calls 5

logNodeOpFunction · 0.85
indexOfMethod · 0.80
errorMethod · 0.80
removeFunction · 0.70
pushMethod · 0.65

Tested by

no test coverage detected