Skip to content

Commit be46754

Browse files
committed
vdom.Helper: createDeltas() => enhance the logic for re-sorting arrays #3116
1 parent 3849a1a commit be46754

3 files changed

Lines changed: 8 additions & 10 deletions

File tree

src/vdom/Helper.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,9 @@ class Helper extends Base {
243243
oldVnodeRoot,
244244
parentId: movedNode.parentNode.id
245245
});
246+
247+
// see: https://github.com/neomjs/neo/issues/3116
248+
movedOldNode.parentNode.childNodes.splice(index, 0, movedOldNode);
246249
} else if (!movedNode && movedOldNode) {
247250
if (newVnode.id === movedOldNode.vnode.id) {
248251
indexDelta = 0;

test/siesta/tests/VdomCalendar.mjs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ StartTest(t => {
4343

4444
t.isDeeplyStrict(deltas, [
4545
{action: 'moveNode', id: 'neo-event-2', index: 0, parentId: 'neo-column-1'},
46-
{innerHTML: '06:00', id: 'neo-event-2__time'},
47-
{action: 'moveNode', id: 'neo-event-1', index: 1, parentId: 'neo-column-1'} // todo: does not hurt, but not needed
46+
{innerHTML: '06:00', id: 'neo-event-2__time'}
4847
], 'deltas got created successfully');
4948

5049
t.diag("Revert operation");
@@ -67,7 +66,6 @@ StartTest(t => {
6766

6867
t.isDeeplyStrict(deltas, [
6968
{action: 'moveNode', id: 'neo-event-1', index: 0, parentId: 'neo-column-1'},
70-
{action: 'moveNode', id: 'neo-event-2', index: 1, parentId: 'neo-column-1'}, // todo: does not hurt, but not needed
7169
{innerHTML: '10:00', id: 'neo-event-2__time'}
7270
], 'deltas got created successfully');
7371
});

test/siesta/tests/VdomHelper.mjs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,8 @@ StartTest(t => {
306306
}, 'vnode got updated successfully');
307307

308308
t.isDeeplyStrict(deltas, [
309-
{action: 'moveNode', id: 'neo-vnode-3', index: 0, parentId: 'neo-vnode-1'},
310-
{action: 'moveNode', id: 'neo-vnode-2', index: 2, parentId: 'neo-vnode-1'}
309+
{action: 'moveNode', id: 'neo-vnode-3', index: 0, parentId: 'neo-vnode-1'},
310+
{action: 'moveNode', id: 'neo-button-1', index: 1, parentId: 'neo-vnode-1'}
311311
], 'deltas got created successfully');
312312

313313
vdom.cn.push(vdom.cn.shift()); // left shift
@@ -333,8 +333,7 @@ StartTest(t => {
333333

334334
t.isDeeplyStrict(deltas, [
335335
{action: 'moveNode', id: 'neo-button-1', index: 0, parentId: 'neo-vnode-1'},
336-
{action: 'moveNode', id: 'neo-vnode-2', index: 1, parentId: 'neo-vnode-1'},
337-
{action: 'moveNode', id: 'neo-vnode-3', index: 2, parentId: 'neo-vnode-1'}
336+
{action: 'moveNode', id: 'neo-vnode-2', index: 1, parentId: 'neo-vnode-1'}
338337
], 'deltas got created successfully');
339338

340339
vdom.cn.unshift(vdom.cn.pop()); // right shift
@@ -359,9 +358,7 @@ StartTest(t => {
359358
}, 'vnode got updated successfully');
360359

361360
t.isDeeplyStrict(deltas, [
362-
{action: 'moveNode', id: 'neo-vnode-3', index: 0, parentId: 'neo-vnode-1'},
363-
{action: 'moveNode', id: 'neo-button-1', index: 1, parentId: 'neo-vnode-1'},
364-
{action: 'moveNode', id: 'neo-vnode-2', index: 2, parentId: 'neo-vnode-1'}
361+
{action: 'moveNode', id: 'neo-vnode-3', index: 0, parentId: 'neo-vnode-1'}
365362
], 'deltas got created successfully');
366363
});
367364

0 commit comments

Comments
 (0)