mol_wire_lib 1.0.1739 → 1.0.1741

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/web.test.js CHANGED
@@ -209,6 +209,12 @@ var $;
209
209
  createDocumentFragment: () => $mol_dom_context.document.createDocumentFragment(),
210
210
  };
211
211
  $.$mol_jsx_frag = '';
212
+ /**
213
+ * JSX adapter that makes DOM tree.
214
+ * Generates global unique ids for every DOM-element by components tree with ids.
215
+ * Ensures all local ids are unique.
216
+ * Can reuse an existing nodes by GUIDs when used inside [`mol_jsx_attach`](https://github.com/hyoo-ru/mam_mol/tree/master/jsx/attach).
217
+ */
212
218
  function $mol_jsx(Elem, props, ...childNodes) {
213
219
  const id = props && props.id || '';
214
220
  const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
@@ -319,6 +325,8 @@ var $;
319
325
 
320
326
  ;
321
327
  "use strict";
328
+ /** @jsx $mol_jsx */
329
+ /** @jsxFrag $mol_jsx_frag */
322
330
  var $;
323
331
  (function ($) {
324
332
  $mol_test({
@@ -424,6 +432,7 @@ var $;
424
432
  "use strict";
425
433
  var $;
426
434
  (function ($) {
435
+ /** Lazy computed lists with native Array interface. $mol_range2_array is mutable but all derived ranges are immutable. */
427
436
  function $mol_range2(item = index => index, size = () => Number.POSITIVE_INFINITY) {
428
437
  const source = typeof item === 'function' ? new $mol_range2_array() : item;
429
438
  if (typeof item !== 'function') {
@@ -472,6 +481,7 @@ var $;
472
481
  }
473
482
  $.$mol_range2 = $mol_range2;
474
483
  class $mol_range2_array extends Array {
484
+ // Lazy
475
485
  concat(...tail) {
476
486
  if (tail.length === 0)
477
487
  return this;
@@ -483,6 +493,7 @@ var $;
483
493
  }
484
494
  return $mol_range2(index => index < this.length ? this[index] : tail[0][index - this.length], () => this.length + tail[0].length);
485
495
  }
496
+ // Lazy
486
497
  filter(check, context) {
487
498
  const filtered = [];
488
499
  let cursor = -1;
@@ -495,13 +506,16 @@ var $;
495
506
  return filtered[index];
496
507
  }, () => cursor < this.length ? Number.POSITIVE_INFINITY : filtered.length);
497
508
  }
509
+ // Diligent
498
510
  forEach(proceed, context) {
499
511
  for (let [key, value] of this.entries())
500
512
  proceed.call(context, value, key, this);
501
513
  }
514
+ // Lazy
502
515
  map(proceed, context) {
503
516
  return $mol_range2(index => proceed.call(context, this[index], index, this), () => this.length);
504
517
  }
518
+ // Diligent
505
519
  reduce(merge, result) {
506
520
  let index = 0;
507
521
  if (arguments.length === 1) {
@@ -512,12 +526,15 @@ var $;
512
526
  }
513
527
  return result;
514
528
  }
529
+ // Lazy
515
530
  toReversed() {
516
531
  return $mol_range2(index => this[this.length - 1 - index], () => this.length);
517
532
  }
533
+ // Lazy
518
534
  slice(from = 0, to = this.length) {
519
535
  return $mol_range2(index => this[from + index], () => Math.min(to, this.length) - from);
520
536
  }
537
+ // Lazy
521
538
  some(check, context) {
522
539
  for (let index = 0; index < this.length; ++index) {
523
540
  if (check.call(context, this[index], index, this))
@@ -710,6 +727,7 @@ var $;
710
727
 
711
728
  ;
712
729
  "use strict";
730
+ /** @jsx $mol_jsx */
713
731
  var $;
714
732
  (function ($) {
715
733
  $mol_test({
@@ -771,6 +789,7 @@ var $;
771
789
  const obj3_copy = { test: 3, obj2: obj2_copy };
772
790
  obj1.obj3 = obj3;
773
791
  obj1_copy.obj3 = obj3_copy;
792
+ // warmup cache
774
793
  $mol_assert_not($mol_compare_deep(obj1, {}));
775
794
  $mol_assert_not($mol_compare_deep(obj2, {}));
776
795
  $mol_assert_not($mol_compare_deep(obj3, {}));
@@ -840,18 +859,34 @@ var $;
840
859
  "use strict";
841
860
  var $;
842
861
  (function ($) {
862
+ /**
863
+ * Argument must be Truthy
864
+ * @deprecated use $mol_assert_equal instead
865
+ */
843
866
  function $mol_assert_ok(value) {
844
867
  if (value)
845
868
  return;
846
869
  $mol_fail(new Error(`${value} ≠ true`));
847
870
  }
848
871
  $.$mol_assert_ok = $mol_assert_ok;
872
+ /**
873
+ * Argument must be Falsy
874
+ * @deprecated use $mol_assert_equal instead
875
+ */
849
876
  function $mol_assert_not(value) {
850
877
  if (!value)
851
878
  return;
852
879
  $mol_fail(new Error(`${value} ≠ false`));
853
880
  }
854
881
  $.$mol_assert_not = $mol_assert_not;
882
+ /**
883
+ * Handler must throw an error.
884
+ * @example
885
+ * $mol_assert_fail( ()=>{ throw new Error( 'Parse error' ) } ) // Passes because throws error
886
+ * $mol_assert_fail( ()=>{ throw new Error( 'Parse error' ) } , 'Parse error' ) // Passes because throws right message
887
+ * $mol_assert_fail( ()=>{ throw new Error( 'Parse error' ) } , Error ) // Passes because throws right class
888
+ * @see https://mol.hyoo.ru/#!section=docs/=9q9dv3_fgxjsf
889
+ */
855
890
  function $mol_assert_fail(handler, ErrorRight) {
856
891
  const fail = $.$mol_fail;
857
892
  try {
@@ -874,10 +909,18 @@ var $;
874
909
  $mol_fail(new Error('Not failed', { cause: { expect: ErrorRight } }));
875
910
  }
876
911
  $.$mol_assert_fail = $mol_assert_fail;
912
+ /** @deprecated Use $mol_assert_equal */
877
913
  function $mol_assert_like(...args) {
878
914
  $mol_assert_equal(...args);
879
915
  }
880
916
  $.$mol_assert_like = $mol_assert_like;
917
+ /**
918
+ * All arguments must not be structural equal to each other.
919
+ * @example
920
+ * $mol_assert_unique( 1 , 2 , 3 ) // Passes
921
+ * $mol_assert_unique( 1 , 1 , 2 ) // Fails because 1 === 1
922
+ * @see https://mol.hyoo.ru/#!section=docs/=9q9dv3_fgxjsf
923
+ */
881
924
  function $mol_assert_unique(...args) {
882
925
  for (let i = 0; i < args.length; ++i) {
883
926
  for (let j = 0; j < args.length; ++j) {
@@ -890,6 +933,13 @@ var $;
890
933
  }
891
934
  }
892
935
  $.$mol_assert_unique = $mol_assert_unique;
936
+ /**
937
+ * All arguments must be structural equal each other.
938
+ * @example
939
+ * $mol_assert_like( [1] , [1] , [1] ) // Passes
940
+ * $mol_assert_like( [1] , [1] , [2] ) // Fails because 1 !== 2
941
+ * @see https://mol.hyoo.ru/#!section=docs/=9q9dv3_fgxjsf
942
+ */
893
943
  function $mol_assert_equal(...args) {
894
944
  for (let i = 1; i < args.length; ++i) {
895
945
  if ($mol_compare_deep(args[0], args[i]))
@@ -1103,6 +1153,7 @@ var $;
1103
1153
  "use strict";
1104
1154
  var $;
1105
1155
  (function ($) {
1156
+ /// @todo right orderinng
1106
1157
  $.$mol_after_mock_queue = [];
1107
1158
  function $mol_after_mock_warp() {
1108
1159
  const queue = $.$mol_after_mock_queue.splice(0);
@@ -1230,6 +1281,7 @@ var $;
1230
1281
 
1231
1282
  ;
1232
1283
  "use strict";
1284
+ /** @jsx $mol_jsx */
1233
1285
  var $;
1234
1286
  (function ($) {
1235
1287
  $mol_test({
@@ -1318,6 +1370,12 @@ var $;
1318
1370
  'return result without errors'() {
1319
1371
  $mol_assert_equal($mol_try(() => false), false);
1320
1372
  },
1373
+ //'return error if thrown'() {
1374
+ //
1375
+ // const error = new Error( '$mol_try test error' )
1376
+ // $mol_assert_equal( $mol_try( ()=> { throw error } ) , error )
1377
+ //
1378
+ //} ,
1321
1379
  });
1322
1380
  })($ || ($ = {}));
1323
1381
 
@@ -1523,6 +1581,7 @@ var $;
1523
1581
  var $;
1524
1582
  (function ($_1) {
1525
1583
  $mol_test({
1584
+ // https://github.com/nin-jin/slides/tree/master/reactivity#component-states
1526
1585
  'Cached channel'($) {
1527
1586
  class App extends $mol_object2 {
1528
1587
  static $ = $;
@@ -1580,6 +1639,7 @@ var $;
1580
1639
  $mol_assert_equal(App.value(5), 21);
1581
1640
  $mol_assert_equal(App.value(), 21);
1582
1641
  },
1642
+ // https://github.com/nin-jin/slides/tree/master/reactivity#wish-consistency
1583
1643
  'Auto recalculation of cached values'($) {
1584
1644
  class App extends $mol_object2 {
1585
1645
  static $ = $;
@@ -1607,6 +1667,7 @@ var $;
1607
1667
  App.xxx(5);
1608
1668
  $mol_assert_equal(App.zzz(), 7);
1609
1669
  },
1670
+ // https://github.com/nin-jin/slides/tree/master/reactivity#wish-reasonability
1610
1671
  'Skip recalculation when actually no dependency changes'($) {
1611
1672
  const log = [];
1612
1673
  class App extends $mol_object2 {
@@ -1640,6 +1701,7 @@ var $;
1640
1701
  App.zzz();
1641
1702
  $mol_assert_like(log, ['zzz', 'yyy', 'xxx', 'xxx', 'yyy']);
1642
1703
  },
1704
+ // https://github.com/nin-jin/slides/tree/master/reactivity#flow-auto
1643
1705
  'Flow: Auto'($) {
1644
1706
  class App extends $mol_object2 {
1645
1707
  static get $() { return $; }
@@ -1677,6 +1739,7 @@ var $;
1677
1739
  $mol_assert_equal(App.result(), 23);
1678
1740
  $mol_assert_equal(App.counter, 4);
1679
1741
  },
1742
+ // https://github.com/nin-jin/slides/tree/master/reactivity#dupes-equality
1680
1743
  'Dupes: Equality'($) {
1681
1744
  let counter = 0;
1682
1745
  class App extends $mol_object2 {
@@ -1700,6 +1763,7 @@ var $;
1700
1763
  App.foo({ numbs: [2] });
1701
1764
  $mol_assert_like(App.bar(), { numbs: [2], count: 2 });
1702
1765
  },
1766
+ // https://github.com/nin-jin/slides/tree/master/reactivity#cycle-fail
1703
1767
  'Cycle: Fail'($) {
1704
1768
  class App extends $mol_object2 {
1705
1769
  static $ = $;
@@ -1724,6 +1788,29 @@ var $;
1724
1788
  ], App, "test", null);
1725
1789
  App.test();
1726
1790
  },
1791
+ // https://github.com/nin-jin/slides/tree/master/reactivity#wish-stability
1792
+ // 'Update deps on push'( $ ) {
1793
+ // class App extends $mol_object2 {
1794
+ // static $ = $
1795
+ // @ $mol_wire_solo
1796
+ // static left( next = false ) {
1797
+ // return next
1798
+ // }
1799
+ // @ $mol_wire_solo
1800
+ // static right( next = false ) {
1801
+ // return next
1802
+ // }
1803
+ // @ $mol_wire_solo
1804
+ // static res( next?: boolean ) {
1805
+ // return this.left( next ) && this.right()
1806
+ // }
1807
+ // }
1808
+ // $mol_assert_equal( App.res(), false )
1809
+ // $mol_assert_equal( App.res( true ), false )
1810
+ // $mol_assert_equal( App.right( true ), true )
1811
+ // $mol_assert_equal( App.res(), true )
1812
+ // } ,
1813
+ // https://github.com/nin-jin/slides/tree/master/reactivity#wish-stability
1727
1814
  'Different order of pull and push'($) {
1728
1815
  class App extends $mol_object2 {
1729
1816
  static $ = $;
@@ -1735,7 +1822,7 @@ var $;
1735
1822
  }
1736
1823
  static slow(next) {
1737
1824
  if (next !== undefined)
1738
- this.slow();
1825
+ this.slow(); // enforce pull before push
1739
1826
  return this.store(next);
1740
1827
  }
1741
1828
  }
@@ -1754,6 +1841,7 @@ var $;
1754
1841
  App.store(777);
1755
1842
  $mol_assert_equal(App.fast(), App.slow(), 777);
1756
1843
  },
1844
+ // https://github.com/nin-jin/slides/tree/master/reactivity#wish-stability
1757
1845
  'Actions inside invariant'($) {
1758
1846
  class App extends $mol_object2 {
1759
1847
  static $ = $;
@@ -1793,6 +1881,7 @@ var $;
1793
1881
  static toggle() {
1794
1882
  const prev = this.checked();
1795
1883
  $mol_assert_unique(this.checked(!prev), prev);
1884
+ // $mol_assert_equal( this.checked() , prev )
1796
1885
  }
1797
1886
  static res() {
1798
1887
  return this.checked();
@@ -1817,6 +1906,39 @@ var $;
1817
1906
  ], App, "test", null);
1818
1907
  await $mol_wire_async(App).test();
1819
1908
  },
1909
+ // // https://github.com/nin-jin/slides/tree/master/reactivity#wish-stability
1910
+ // 'Stable order of multiple root'( $ ) {
1911
+ // class App extends $mol_object2 {
1912
+ // static $ = $
1913
+ // static counter = 0
1914
+ // @ $mol_wire_solo
1915
+ // static left_trigger( next = 0 ) {
1916
+ // return next
1917
+ // }
1918
+ // @ $mol_wire_solo
1919
+ // static left_root() {
1920
+ // this.left_trigger()
1921
+ // return ++ this.counter
1922
+ // }
1923
+ // @ $mol_wire_solo
1924
+ // static right_trigger( next = 0 ) {
1925
+ // return next
1926
+ // }
1927
+ // @ $mol_wire_solo
1928
+ // static right_root() {
1929
+ // this.right_trigger()
1930
+ // return ++ this.counter
1931
+ // }
1932
+ // }
1933
+ // $mol_assert_equal( App.left_root(), 1 )
1934
+ // $mol_assert_equal( App.right_root(), 2 )
1935
+ // App.right_trigger( 1 )
1936
+ // App.left_trigger( 1 )
1937
+ // $mol_wire_fiber.sync()
1938
+ // $mol_assert_equal( App.right_root(), 4 )
1939
+ // $mol_assert_equal( App.left_root(), 3 )
1940
+ // } ,
1941
+ // https://github.com/nin-jin/slides/tree/master/reactivity#error-store
1820
1942
  'Restore after error'($) {
1821
1943
  class App extends $mol_object2 {
1822
1944
  static get $() { return $; }
@@ -1914,6 +2036,7 @@ var $;
1914
2036
  App.showing(true);
1915
2037
  $mol_assert_unique(App.render(), details);
1916
2038
  },
2039
+ // https://github.com/nin-jin/slides/tree/master/reactivity#wish-stability
1917
2040
  async 'Hold pubs while wait async task'($) {
1918
2041
  class App extends $mol_object2 {
1919
2042
  static $ = $;