neo.mjs 4.0.35 → 4.0.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neo.mjs",
3
- "version": "4.0.35",
3
+ "version": "4.0.38",
4
4
  "description": "The webworkers driven UI framework",
5
5
  "type": "module",
6
6
  "repository": {
@@ -40,8 +40,8 @@
40
40
  "autoprefixer": "^10.4.7",
41
41
  "chalk": "^5.0.1",
42
42
  "clean-webpack-plugin": "^4.0.0",
43
- "commander": "^9.2.0",
44
- "cssnano": "^5.1.8",
43
+ "commander": "^9.3.0",
44
+ "cssnano": "^5.1.10",
45
45
  "envinfo": "^7.8.1",
46
46
  "fs-extra": "^10.1.0",
47
47
  "highlightjs-line-numbers.js": "^2.8.0",
@@ -753,9 +753,7 @@ class Base extends CoreBase {
753
753
  * @protected
754
754
  */
755
755
  beforeSetModel(value, oldValue) {
756
- if (oldValue) {
757
- oldValue.destroy();
758
- }
756
+ oldValue?.destroy();
759
757
 
760
758
  if (value) {
761
759
  let me = this,
@@ -852,12 +850,11 @@ class Base extends CoreBase {
852
850
 
853
851
  me.domListeners = [];
854
852
 
855
- me.controller?.destroy();
856
- me.controller = null;
853
+ me.controller = null; // triggers destroy()
857
854
 
858
855
  me.reference && me.getController()?.removeReference(me); // remove own reference from parent controllers
859
856
 
860
- me.model?.destroy();
857
+ me.model = null; // triggers destroy()
861
858
 
862
859
  me.bind && parentModel?.removeBindings(me.id);
863
860
 
@@ -36,6 +36,15 @@ class Base extends CoreBase {
36
36
  HashHistory.on('change', this.onHashChange, this);
37
37
  }
38
38
 
39
+ /**
40
+ * @param args
41
+ */
42
+ destroy(...args) {
43
+ HashHistory.un('change', this.onHashChange, this);
44
+
45
+ super.destroy(...args);
46
+ }
47
+
39
48
  /**
40
49
  * Placeholder method which gets triggered when the hash inside the browser url changes
41
50
  * @param {Object} value
@@ -111,7 +111,12 @@ class Observable extends Base {
111
111
  eventConfig.fn = eventConfig.scope[eventConfig.fn];
112
112
  }
113
113
 
114
- eventConfig.fn.apply(eventConfig.scope || me, eventConfig.data ? args.concat(eventConfig.data) : args);
114
+ // remove the listener, in case the scope no longer exists
115
+ if (eventConfig.scope && !eventConfig.scope.id) {
116
+ listeners[name].splice(i, 1);
117
+ } else {
118
+ eventConfig.fn.apply(eventConfig.scope || me, eventConfig.data ? args.concat(eventConfig.data) : args);
119
+ }
115
120
  }
116
121
  }
117
122
  }
@@ -95,9 +95,7 @@ class NeoArray extends Base {
95
95
  items.forEach(item => {
96
96
  index = arr.indexOf(item);
97
97
 
98
- if (index > -1) {
99
- arr.splice(index, 1);
100
- }
98
+ index > -1 && arr.splice(index, 1);
101
99
  });
102
100
  }
103
101
 
@@ -243,6 +243,9 @@ class Helper extends Base {
243
243
  oldVnodeRoot,
244
244
  parentId: movedNode.parentNode.id
245
245
  });
246
+
247
+ // see: https://github.com/neomjs/neo/issues/3116
248
+ movedOldNode.parentNode.childNodes.splice(index, 0, movedOldNode);
246
249
  } else if (!movedNode && movedOldNode) {
247
250
  if (newVnode.id === movedOldNode.vnode.id) {
248
251
  indexDelta = 0;
@@ -43,8 +43,7 @@ StartTest(t => {
43
43
 
44
44
  t.isDeeplyStrict(deltas, [
45
45
  {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'}
48
47
  ], 'deltas got created successfully');
49
48
 
50
49
  t.diag("Revert operation");
@@ -67,7 +66,6 @@ StartTest(t => {
67
66
 
68
67
  t.isDeeplyStrict(deltas, [
69
68
  {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
71
69
  {innerHTML: '10:00', id: 'neo-event-2__time'}
72
70
  ], 'deltas got created successfully');
73
71
  });
@@ -306,8 +306,8 @@ StartTest(t => {
306
306
  }, 'vnode got updated successfully');
307
307
 
308
308
  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'}
311
311
  ], 'deltas got created successfully');
312
312
 
313
313
  vdom.cn.push(vdom.cn.shift()); // left shift
@@ -333,8 +333,7 @@ StartTest(t => {
333
333
 
334
334
  t.isDeeplyStrict(deltas, [
335
335
  {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'}
338
337
  ], 'deltas got created successfully');
339
338
 
340
339
  vdom.cn.unshift(vdom.cn.pop()); // right shift
@@ -359,9 +358,7 @@ StartTest(t => {
359
358
  }, 'vnode got updated successfully');
360
359
 
361
360
  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'}
365
362
  ], 'deltas got created successfully');
366
363
  });
367
364
 
@@ -548,7 +545,89 @@ StartTest(t => {
548
545
  {attributes: {tabIndex: '-1'}, childNodes: [], className: ['neo-list-item'], id: 'neo-list-1__rwaters', innerHTML: 'Rich', nodeName: 'li', style: {}, vtype: 'vnode'},
549
546
  {attributes: {tabIndex: '-1'}, childNodes: [], className: ['neo-list-item'], id: 'neo-list-1__tobiu', innerHTML: 'Tobias', nodeName: 'li', style: {}, vtype: 'vnode'}
550
547
  ], 'vnode got updated successfully');
548
+ });
549
+
550
+ t.it('Sorting', t => {
551
+ t.diag("Creating a sorted array");
552
+
553
+ vdom =
554
+ {id: 'root', cn: [
555
+ {id: '0', html: 'g'},
556
+ {id: '1', html: 'g'},
557
+ {id: '2', html: 'g'},
558
+ {id: '3', html: 'g'},
559
+ {id: '4', html: 'm'},
560
+ {id: '5', html: 'm'},
561
+ {id: '6', html: 'w'},
562
+ {id: '7', html: 'w'},
563
+ {id: '8', html: 'w'},
564
+ {id: '9', html: 'w'}
565
+ ]};
566
+
567
+ vnode = VdomHelper.create(vdom);
568
+
569
+ t.isDeeplyStrict(vnode, {
570
+ attributes: {},
571
+ className : [],
572
+ id : 'root',
573
+ innerHTML : undefined,
574
+ nodeName : 'div',
575
+ outerHTML : t.any(String),
576
+ style : {},
577
+ vtype : 'vnode',
578
+
579
+ childNodes: [
580
+ {attributes: {}, childNodes: [], className: [], id: '0', innerHTML: 'g', nodeName: 'div', style: {}, vtype: 'vnode'},
581
+ {attributes: {}, childNodes: [], className: [], id: '1', innerHTML: 'g', nodeName: 'div', style: {}, vtype: 'vnode'},
582
+ {attributes: {}, childNodes: [], className: [], id: '2', innerHTML: 'g', nodeName: 'div', style: {}, vtype: 'vnode'},
583
+ {attributes: {}, childNodes: [], className: [], id: '3', innerHTML: 'g', nodeName: 'div', style: {}, vtype: 'vnode'},
584
+ {attributes: {}, childNodes: [], className: [], id: '4', innerHTML: 'm', nodeName: 'div', style: {}, vtype: 'vnode'},
585
+ {attributes: {}, childNodes: [], className: [], id: '5', innerHTML: 'm', nodeName: 'div', style: {}, vtype: 'vnode'},
586
+ {attributes: {}, childNodes: [], className: [], id: '6', innerHTML: 'w', nodeName: 'div', style: {}, vtype: 'vnode'},
587
+ {attributes: {}, childNodes: [], className: [], id: '7', innerHTML: 'w', nodeName: 'div', style: {}, vtype: 'vnode'},
588
+ {attributes: {}, childNodes: [], className: [], id: '8', innerHTML: 'w', nodeName: 'div', style: {}, vtype: 'vnode'},
589
+ {attributes: {}, childNodes: [], className: [], id: '9', innerHTML: 'w', nodeName: 'div', style: {}, vtype: 'vnode'}
590
+ ]
591
+ }, 'vnode got created successfully');
592
+
593
+ vdom.cn = [
594
+ {id: '9', html: 'w'},
595
+ {id: '8', html: 'w'},
596
+ {id: '7', html: 'w'},
597
+ {id: '6', html: 'w'},
598
+ {id: '4', html: 'm'},
599
+ {id: '5', html: 'm'},
600
+ {id: '3', html: 'g'},
601
+ {id: '2', html: 'g'},
602
+ {id: '1', html: 'g'},
603
+ {id: '0', html: 'g'}
604
+ ];
605
+
606
+ output = VdomHelper.update({vdom: vdom, vnode: vnode}); deltas = output.deltas; vnode = output.vnode;
607
+
608
+ t.isDeeplyStrict(vnode, {
609
+ attributes: {},
610
+ className : [],
611
+ id : 'root',
612
+ innerHTML : undefined,
613
+ nodeName : 'div',
614
+ style : {},
615
+ vtype : 'vnode',
616
+
617
+ childNodes: [
618
+ {attributes: {}, childNodes: [], className: [], id: '9', innerHTML: 'w', nodeName: 'div', style: {}, vtype: 'vnode'},
619
+ {attributes: {}, childNodes: [], className: [], id: '8', innerHTML: 'w', nodeName: 'div', style: {}, vtype: 'vnode'},
620
+ {attributes: {}, childNodes: [], className: [], id: '7', innerHTML: 'w', nodeName: 'div', style: {}, vtype: 'vnode'},
621
+ {attributes: {}, childNodes: [], className: [], id: '6', innerHTML: 'w', nodeName: 'div', style: {}, vtype: 'vnode'},
622
+ {attributes: {}, childNodes: [], className: [], id: '4', innerHTML: 'm', nodeName: 'div', style: {}, vtype: 'vnode'},
623
+ {attributes: {}, childNodes: [], className: [], id: '5', innerHTML: 'm', nodeName: 'div', style: {}, vtype: 'vnode'},
624
+ {attributes: {}, childNodes: [], className: [], id: '3', innerHTML: 'g', nodeName: 'div', style: {}, vtype: 'vnode'},
625
+ {attributes: {}, childNodes: [], className: [], id: '2', innerHTML: 'g', nodeName: 'div', style: {}, vtype: 'vnode'},
626
+ {attributes: {}, childNodes: [], className: [], id: '1', innerHTML: 'g', nodeName: 'div', style: {}, vtype: 'vnode'},
627
+ {attributes: {}, childNodes: [], className: [], id: '0', innerHTML: 'g', nodeName: 'div', style: {}, vtype: 'vnode'}
628
+ ]
629
+ }, 'vnode got updated successfully');
551
630
 
552
- // console.log(deltas);
631
+ console.log(deltas);
553
632
  });
554
633
  });