Skip to content
This repository has been archived by the owner on Jul 30, 2018. It is now read-only.

Fix bug, add tests, update i18n version #85

Merged
merged 2 commits into from
Nov 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"peerDependencies": {
"@dojo/core": "~0.2.1",
"@dojo/has": "~0.1.0",
"@dojo/i18n": "~0.1.1",
"@dojo/i18n": "~0.2.0",
"@dojo/shim": "~0.2.2",
"@dojo/widget-core": "~0.2.0"
},
Expand Down
8 changes: 4 additions & 4 deletions src/support/d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,21 @@ function findByKey(
if (!target.children) {
return {};
}
let found: FoundNodeInfo<WNode | HNode> | undefined;
let nodeInfo: FoundNodeInfo<WNode | HNode> | undefined;
target.children
.forEach((child, index) => {
if (isNode(child)) {
if (found) {
if (nodeInfo && nodeInfo.found) {
if (findByKey(child, key, target, index).found) {
console.warn(`Duplicate key of "${typeof key === 'object' ? JSON.stringify(key) : key }" found.`);
}
}
else {
found = findByKey(child, key, target, index);
nodeInfo = findByKey(child, key, target, index);
}
}
});
return found || {};
return nodeInfo || {};
}

function findByIndex(
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/support/d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ registerSuite('support/virtualDom', {

'key is in child'() {
assertRender(findKey(v('div', { key: 'bar' }, [ v('span', { key: 'foo' }), 'foo', null ]), 'foo')!, v('span', { key: 'foo' }), 'should find child node');
assertRender(findKey(v('div', { key: 'bar' }, [ v('span', { key: 'foo' }), v('span', { key: 'baz' }), 'foo', null ]), 'baz')!, v('span', { key: 'baz' }), 'should find child node');
},

'key is object'() {
Expand Down Expand Up @@ -426,7 +427,13 @@ registerSuite('support/virtualDom', {
])
]);

const noDuplicates = v('div', { key: 'foo' }, [
v('span', { key: 'parent1' }),
v('span', { key: 'parent2' })
]);

assertRender(findKey(fixture, key)!, v('i', { key, id: 'i1' }), 'should find first key');
assertRender(findKey(noDuplicates, 'parent2')!, v('span', { key: 'parent2' }), 'should find key');
assert.strictEqual(warnStub.callCount, 1, 'should have been called once');
assert.strictEqual(warnStub.lastCall.args[0], 'Duplicate key of "{}" found.', 'should have logged duplicate key');
warnStub.restore();
Expand Down