Skip to content

Commit

Permalink
prepend element of different tag type
Browse files Browse the repository at this point in the history
  • Loading branch information
mbasso committed May 1, 2017
1 parent 30db182 commit ad8e90f
Show file tree
Hide file tree
Showing 7 changed files with 1,348 additions and 1,283 deletions.
Binary file modified compiled/asm-dom.bc
Binary file not shown.
Binary file modified compiled/asm-dom.o
Binary file not shown.
2 changes: 1 addition & 1 deletion compiled/asmjs/asm-dom.asm.js

Large diffs are not rendered by default.

2,613 changes: 1,341 additions & 1,272 deletions compiled/wasm/asm-dom.asm.js

Large diffs are not rendered by default.

Binary file modified compiled/wasm/asm-dom.wasm
Binary file not shown.
14 changes: 6 additions & 8 deletions src/cpp/Main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ bool sameVnode(const VNode* __restrict__ const vnode1, const VNode* __restrict__
};

std::map<std::string, int>* createKeyToOldIdx(const std::vector<VNode*>& children, const int beginIdx, const int endIdx) {
std::size_t i = beginIdx;
std::map<std::string, int>* map = new std::map<std::string, int>();
for (; i <= endIdx; ++i) {
for (int i = beginIdx; i <= endIdx; ++i) {
if (!children[i]->key.empty()) {
map->insert(std::make_pair(children[i]->key, i));
}
Expand Down Expand Up @@ -113,10 +112,10 @@ void updateChildren(
std::vector<VNode*>& oldCh,
std::vector<VNode*>& newCh
) {
std::size_t oldStartIdx = 0;
std::size_t newStartIdx = 0;
std::size_t oldEndIdx = oldCh.size() - 1;
std::size_t newEndIdx = newCh.size() - 1;
int oldStartIdx = 0;
int newStartIdx = 0;
int oldEndIdx = oldCh.size() - 1;
int newEndIdx = newCh.size() - 1;
VNode* oldStartVnode = oldCh[0];
VNode* oldEndVnode = oldCh[oldEndIdx];
VNode* newStartVnode = newCh[0];
Expand Down Expand Up @@ -170,8 +169,6 @@ void updateChildren(
}, parentElm, createElm(newStartVnode), oldStartVnode->elm);
} else {
patchVnode(elmToMove, newStartVnode);
deleteVNode(elmToMove);
elmToMove = NULL;
oldKeyToIdx->erase(newStartVnode->key);
EM_ASM_({
window['asmDomHelpers']['domApi']['insertBefore']($0, $1, $2);
Expand All @@ -191,6 +188,7 @@ void updateChildren(
removeVnodes(oldCh, oldStartIdx, oldEndIdx);
}
delete oldKeyToIdx;
oldKeyToIdx = NULL;
};

void patchVnode(VNode* __restrict__ const oldVnode, VNode* __restrict__ const vnode) {
Expand Down
2 changes: 0 additions & 2 deletions test/patch.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,6 @@ describe('patch', function testPatch() {
vdom.deleteVNode(vnode2);
});

/*
it('should prepend element of different tag type', () => {
const vnode1 = h('div', [h('span', 'World')]);
const vnode2 = h('div', [h('div', 'Hello'), h('span', 'World')]);
Expand All @@ -624,7 +623,6 @@ describe('patch', function testPatch() {
expect(map(inner, elm.children)).toEqual(['Hello', 'World']);
vdom.deleteVNode(vnode2);
});
*/

it('should remove elements', () => {
const vnode1 = h('div', [h('span', 'One'), h('span', 'Two'), h('span', 'Three')]);
Expand Down

0 comments on commit ad8e90f

Please sign in to comment.