Skip to content

Commit

Permalink
Ported Keyed algo tests from Kivi + added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Havunen committed Nov 13, 2016
1 parent 2ef9bad commit 8981471
Show file tree
Hide file tree
Showing 7 changed files with 415 additions and 25 deletions.
10 changes: 3 additions & 7 deletions packages/inferno/dist/inferno-compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -780,11 +780,9 @@ function processElement(flags, vNode, dom) {
}
}

// import {
// getIncrementalId,
// componentIdMap
// } from './devtools';
function patch(lastVNode, nextVNode, parentDom, lifecycle, context, isSVG) {
// TODO: Our nodes are not immutable and hoisted nodes get cloned. Is there any possibility to make this check true
// TODO: Remove check or write test case to verify this behavior
if (lastVNode !== nextVNode) {
var lastFlags = lastVNode.flags;
var nextFlags = nextVNode.flags;
Expand Down Expand Up @@ -1112,9 +1110,7 @@ function patchKeyedChildren(a, b, dom, lifecycle, context, isSVG) {
return;
}
else if (bLength === 0) {
if (aLength !== 0) {
removeAllChildren(dom, a, lifecycle, false);
}
removeAllChildren(dom, a, lifecycle, false);
return;
}
// Step 1
Expand Down
2 changes: 1 addition & 1 deletion packages/inferno/dist/inferno-compat.min.js

Large diffs are not rendered by default.

10 changes: 3 additions & 7 deletions packages/inferno/dist/inferno.js
Original file line number Diff line number Diff line change
Expand Up @@ -634,11 +634,9 @@ function processElement(flags, vNode, dom) {
}
}

// import {
// getIncrementalId,
// componentIdMap
// } from './devtools';
function patch(lastVNode, nextVNode, parentDom, lifecycle, context, isSVG) {
// TODO: Our nodes are not immutable and hoisted nodes get cloned. Is there any possibility to make this check true
// TODO: Remove check or write test case to verify this behavior
if (lastVNode !== nextVNode) {
var lastFlags = lastVNode.flags;
var nextFlags = nextVNode.flags;
Expand Down Expand Up @@ -966,9 +964,7 @@ function patchKeyedChildren(a, b, dom, lifecycle, context, isSVG) {
return;
}
else if (bLength === 0) {
if (aLength !== 0) {
removeAllChildren(dom, a, lifecycle, false);
}
removeAllChildren(dom, a, lifecycle, false);
return;
}
// Step 1
Expand Down
2 changes: 1 addition & 1 deletion packages/inferno/dist/inferno.min.js

Large diffs are not rendered by default.

87 changes: 87 additions & 0 deletions src/DOM/__tests__/children.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1211,5 +1211,92 @@ describe('Children - (JSX)', () => {

expect(container.innerHTML).to.eql('<div><div>3</div><div>2</div><div>11</div></div>');
});

it('Should handle previous being empty array', () => {
const CollectionKeyed = ({children}) => (
<div hasKeyedChildren>
{children}
</div>
);

const child = [];
render(
<CollectionKeyed>
{child}
</CollectionKeyed>
,container
);

expect(container.innerHTML).to.eql('<div></div>');

render(
<CollectionKeyed>
<div key="1">1</div>
<div key="2">2</div>
<div key="3">3</div>
</CollectionKeyed>
,container
);

expect(container.innerHTML).to.eql('<div><div>1</div><div>2</div><div>3</div></div>');
});

it('Should handle next being empty array', () => {
const CollectionKeyed = ({children}) => (
<div hasKeyedChildren>
{children}
</div>
);

render(
<CollectionKeyed>
<div key="1">1</div>
<div key="2">2</div>
<div key="3">3</div>
</CollectionKeyed>
,container
);

expect(container.innerHTML).to.eql('<div><div>1</div><div>2</div><div>3</div></div>');

const child = [];
render(
<CollectionKeyed>
{child}
</CollectionKeyed>
,container
);

expect(container.innerHTML).to.eql('<div></div>');
});

it('Should handle last/next being empty', () => {
const CollectionKeyed = ({children}) => (
<div hasKeyedChildren>
{children}
</div>
);

const child = [];
render(
<CollectionKeyed>
{child}
</CollectionKeyed>
,container
);

expect(container.innerHTML).to.eql('<div></div>');

const childB = [];

render(
<CollectionKeyed>
{childB}
</CollectionKeyed>
,container
);

expect(container.innerHTML).to.eql('<div></div>');
});
});
});
Loading

0 comments on commit 8981471

Please sign in to comment.