Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function patchInto(target, node) {
const targetIsArray = Array.isArray(target)
const nodeIsArray = Array.isArray(node)
if (nodeIsArray)
mapPrimitiveNodes(node)
// First render inside an Element
if (target.elm === undefined) {
patch(
VNode('dummy', {}, [], undefined, target),
VNode('dummy', {}, nodeIsArray ? node : [node])
)
if (nodeIsArray)
node.elm = target
}
// Update using a previous VNode or VNode[] to patch against
else {
if (targetIsArray) {
patch(
VNode('dummy', {}, target, undefined, target.elm),
VNode('dummy', {}, nodeIsArray ? node : [node])
)
}
else {
patch(target, node)
}
// First render inside an Element
if (target.elm === undefined) {
patch(
VNode('dummy', {}, [], undefined, target),
VNode('dummy', {}, nodeIsArray ? node : [node])
)
if (nodeIsArray)
node.elm = target
}
// Update using a previous VNode or VNode[] to patch against
else {
if (targetIsArray) {
patch(
VNode('dummy', {}, target, undefined, target.elm),
VNode('dummy', {}, nodeIsArray ? node : [node])
)
}
else {
patch(target, node)
}
if (nodeIsArray)
node.elm = target.elm
}
}
function patchInto(target, node) {
const targetIsArray = Array.isArray(target)
const nodeIsArray = Array.isArray(node)
if (nodeIsArray)
mapPrimitiveNodes(node)
// First render inside an Element
if (target.elm === undefined) {
patch(
VNode('dummy', {}, [], undefined, target),
VNode('dummy', {}, nodeIsArray ? node : [node])
)
if (nodeIsArray)
node.elm = target
}
// Update using a previous VNode or VNode[] to patch against
else {
if (targetIsArray) {
patch(
VNode('dummy', {}, target, undefined, target.elm),
VNode('dummy', {}, nodeIsArray ? node : [node])
)
}
else {
patch(target, node)
// First render inside an Element
if (target.elm === undefined) {
patch(
VNode('dummy', {}, [], undefined, target),
VNode('dummy', {}, nodeIsArray ? node : [node])
)
if (nodeIsArray)
node.elm = target
}
// Update using a previous VNode or VNode[] to patch against
else {
if (targetIsArray) {
patch(
VNode('dummy', {}, target, undefined, target.elm),
VNode('dummy', {}, nodeIsArray ? node : [node])
)
}
else {
patch(target, node)
}
if (nodeIsArray)
node.elm = target.elm
}
}
it("should convert nodes with children", () => {
const ul = doc.createElement('ul');
ul.innerHTML = "<li>One</li><li>Fish</li><li>Two</li><li>Fish</li>";
expect(virtualizeNodes(ul, opts)).to.deep.equal(
extendVnode(h('ul', [
extendVnode(h('li', [ extendVnode(VNode(undefined, undefined, undefined, 'One'), ul.childNodes[0].firstChild) ]), ul.childNodes[0]),
extendVnode(h('li', [ extendVnode(VNode(undefined, undefined, undefined, 'Fish'), ul.childNodes[1].firstChild) ]), ul.childNodes[1]),
extendVnode(h('li', [ extendVnode(VNode(undefined, undefined, undefined, 'Two'), ul.childNodes[2].firstChild) ]), ul.childNodes[2]),
extendVnode(h('li', [ extendVnode(VNode(undefined, undefined, undefined, 'Fish'), ul.childNodes[3].firstChild) ]), ul.childNodes[3])
]), ul)
);
});
it("should convert nodes with children", () => {
const ul = doc.createElement('ul');
ul.innerHTML = "<li>One</li><li>Fish</li><li>Two</li><li>Fish</li>";
expect(virtualizeNodes(ul, opts)).to.deep.equal(
extendVnode(h('ul', [
extendVnode(h('li', [ extendVnode(VNode(undefined, undefined, undefined, 'One'), ul.childNodes[0].firstChild) ]), ul.childNodes[0]),
extendVnode(h('li', [ extendVnode(VNode(undefined, undefined, undefined, 'Fish'), ul.childNodes[1].firstChild) ]), ul.childNodes[1]),
extendVnode(h('li', [ extendVnode(VNode(undefined, undefined, undefined, 'Two'), ul.childNodes[2].firstChild) ]), ul.childNodes[2]),
extendVnode(h('li', [ extendVnode(VNode(undefined, undefined, undefined, 'Fish'), ul.childNodes[3].firstChild) ]), ul.childNodes[3])
]), ul)
);
});
const emptyNode = () => VNode('!', {}, [], undefined, undefined)