mol_wire_dom 0.0.1721 → 0.0.1723

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
@@ -134,6 +134,12 @@ var $;
134
134
  createDocumentFragment: () => $mol_dom_context.document.createDocumentFragment(),
135
135
  };
136
136
  $.$mol_jsx_frag = '';
137
+ /**
138
+ * JSX adapter that makes DOM tree.
139
+ * Generates global unique ids for every DOM-element by components tree with ids.
140
+ * Ensures all local ids are unique.
141
+ * Can reuse an existing nodes by GUIDs when used inside [`mol_jsx_attach`](https://github.com/hyoo-ru/mam_mol/tree/master/jsx/attach).
142
+ */
137
143
  function $mol_jsx(Elem, props, ...childNodes) {
138
144
  const id = props && props.id || '';
139
145
  const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
@@ -244,6 +250,8 @@ var $;
244
250
 
245
251
  ;
246
252
  "use strict";
253
+ /** @jsx $mol_jsx */
254
+ /** @jsxFrag $mol_jsx_frag */
247
255
  var $;
248
256
  (function ($) {
249
257
  $mol_test({
@@ -349,6 +357,7 @@ var $;
349
357
  "use strict";
350
358
  var $;
351
359
  (function ($) {
360
+ /** Lazy computed lists with native Array interface. $mol_range2_array is mutable but all derived ranges are immutable. */
352
361
  function $mol_range2(item = index => index, size = () => Number.POSITIVE_INFINITY) {
353
362
  const source = typeof item === 'function' ? new $mol_range2_array() : item;
354
363
  if (typeof item !== 'function') {
@@ -397,6 +406,7 @@ var $;
397
406
  }
398
407
  $.$mol_range2 = $mol_range2;
399
408
  class $mol_range2_array extends Array {
409
+ // Lazy
400
410
  concat(...tail) {
401
411
  if (tail.length === 0)
402
412
  return this;
@@ -408,6 +418,7 @@ var $;
408
418
  }
409
419
  return $mol_range2(index => index < this.length ? this[index] : tail[0][index - this.length], () => this.length + tail[0].length);
410
420
  }
421
+ // Lazy
411
422
  filter(check, context) {
412
423
  const filtered = [];
413
424
  let cursor = -1;
@@ -420,13 +431,16 @@ var $;
420
431
  return filtered[index];
421
432
  }, () => cursor < this.length ? Number.POSITIVE_INFINITY : filtered.length);
422
433
  }
434
+ // Diligent
423
435
  forEach(proceed, context) {
424
436
  for (let [key, value] of this.entries())
425
437
  proceed.call(context, value, key, this);
426
438
  }
439
+ // Lazy
427
440
  map(proceed, context) {
428
441
  return $mol_range2(index => proceed.call(context, this[index], index, this), () => this.length);
429
442
  }
443
+ // Diligent
430
444
  reduce(merge, result) {
431
445
  let index = 0;
432
446
  if (arguments.length === 1) {
@@ -437,12 +451,15 @@ var $;
437
451
  }
438
452
  return result;
439
453
  }
454
+ // Lazy
440
455
  toReversed() {
441
456
  return $mol_range2(index => this[this.length - 1 - index], () => this.length);
442
457
  }
458
+ // Lazy
443
459
  slice(from = 0, to = this.length) {
444
460
  return $mol_range2(index => this[from + index], () => Math.min(to, this.length) - from);
445
461
  }
462
+ // Lazy
446
463
  some(check, context) {
447
464
  for (let index = 0; index < this.length; ++index) {
448
465
  if (check.call(context, this[index], index, this))
@@ -635,6 +652,7 @@ var $;
635
652
 
636
653
  ;
637
654
  "use strict";
655
+ /** @jsx $mol_jsx */
638
656
  var $;
639
657
  (function ($) {
640
658
  $mol_test({
@@ -696,6 +714,7 @@ var $;
696
714
  const obj3_copy = { test: 3, obj2: obj2_copy };
697
715
  obj1.obj3 = obj3;
698
716
  obj1_copy.obj3 = obj3_copy;
717
+ // warmup cache
699
718
  $mol_assert_not($mol_compare_deep(obj1, {}));
700
719
  $mol_assert_not($mol_compare_deep(obj2, {}));
701
720
  $mol_assert_not($mol_compare_deep(obj3, {}));
@@ -765,18 +784,34 @@ var $;
765
784
  "use strict";
766
785
  var $;
767
786
  (function ($) {
787
+ /**
788
+ * Argument must be Truthy
789
+ * @deprecated use $mol_assert_equal instead
790
+ */
768
791
  function $mol_assert_ok(value) {
769
792
  if (value)
770
793
  return;
771
794
  $mol_fail(new Error(`${value} ≠ true`));
772
795
  }
773
796
  $.$mol_assert_ok = $mol_assert_ok;
797
+ /**
798
+ * Argument must be Falsy
799
+ * @deprecated use $mol_assert_equal instead
800
+ */
774
801
  function $mol_assert_not(value) {
775
802
  if (!value)
776
803
  return;
777
804
  $mol_fail(new Error(`${value} ≠ false`));
778
805
  }
779
806
  $.$mol_assert_not = $mol_assert_not;
807
+ /**
808
+ * Handler must throw an error.
809
+ * @example
810
+ * $mol_assert_fail( ()=>{ throw new Error( 'Parse error' ) } ) // Passes because throws error
811
+ * $mol_assert_fail( ()=>{ throw new Error( 'Parse error' ) } , 'Parse error' ) // Passes because throws right message
812
+ * $mol_assert_fail( ()=>{ throw new Error( 'Parse error' ) } , Error ) // Passes because throws right class
813
+ * @see https://mol.hyoo.ru/#!section=docs/=9q9dv3_fgxjsf
814
+ */
780
815
  function $mol_assert_fail(handler, ErrorRight) {
781
816
  const fail = $.$mol_fail;
782
817
  try {
@@ -799,10 +834,18 @@ var $;
799
834
  $mol_fail(new Error('Not failed', { cause: { expect: ErrorRight } }));
800
835
  }
801
836
  $.$mol_assert_fail = $mol_assert_fail;
837
+ /** @deprecated Use $mol_assert_equal */
802
838
  function $mol_assert_like(...args) {
803
839
  $mol_assert_equal(...args);
804
840
  }
805
841
  $.$mol_assert_like = $mol_assert_like;
842
+ /**
843
+ * All arguments must not be structural equal to each other.
844
+ * @example
845
+ * $mol_assert_unique( 1 , 2 , 3 ) // Passes
846
+ * $mol_assert_unique( 1 , 1 , 2 ) // Fails because 1 === 1
847
+ * @see https://mol.hyoo.ru/#!section=docs/=9q9dv3_fgxjsf
848
+ */
806
849
  function $mol_assert_unique(...args) {
807
850
  for (let i = 0; i < args.length; ++i) {
808
851
  for (let j = 0; j < args.length; ++j) {
@@ -815,6 +858,13 @@ var $;
815
858
  }
816
859
  }
817
860
  $.$mol_assert_unique = $mol_assert_unique;
861
+ /**
862
+ * All arguments must be structural equal each other.
863
+ * @example
864
+ * $mol_assert_like( [1] , [1] , [1] ) // Passes
865
+ * $mol_assert_like( [1] , [1] , [2] ) // Fails because 1 !== 2
866
+ * @see https://mol.hyoo.ru/#!section=docs/=9q9dv3_fgxjsf
867
+ */
818
868
  function $mol_assert_equal(...args) {
819
869
  for (let i = 1; i < args.length; ++i) {
820
870
  if ($mol_compare_deep(args[0], args[i]))
@@ -1028,6 +1078,7 @@ var $;
1028
1078
  "use strict";
1029
1079
  var $;
1030
1080
  (function ($) {
1081
+ /// @todo right orderinng
1031
1082
  $.$mol_after_mock_queue = [];
1032
1083
  function $mol_after_mock_warp() {
1033
1084
  const queue = $.$mol_after_mock_queue.splice(0);
@@ -1155,6 +1206,7 @@ var $;
1155
1206
 
1156
1207
  ;
1157
1208
  "use strict";
1209
+ /** @jsx $mol_jsx */
1158
1210
  var $;
1159
1211
  (function ($) {
1160
1212
  $mol_test({
@@ -1243,6 +1295,12 @@ var $;
1243
1295
  'return result without errors'() {
1244
1296
  $mol_assert_equal($mol_try(() => false), false);
1245
1297
  },
1298
+ //'return error if thrown'() {
1299
+ //
1300
+ // const error = new Error( '$mol_try test error' )
1301
+ // $mol_assert_equal( $mol_try( ()=> { throw error } ) , error )
1302
+ //
1303
+ //} ,
1246
1304
  });
1247
1305
  })($ || ($ = {}));
1248
1306
 
@@ -1309,6 +1367,7 @@ var $;
1309
1367
  "use strict";
1310
1368
  var $;
1311
1369
  (function ($) {
1370
+ /** Convert a pseudo-synchronous (Suspense API) API to an explicit asynchronous one (for integrating with external systems). */
1312
1371
  function $mol_wire_async(obj) {
1313
1372
  let fiber;
1314
1373
  const temp = $mol_wire_task.getter(obj);
@@ -1420,6 +1479,10 @@ var $;
1420
1479
  props[field] = get_val;
1421
1480
  return get_val;
1422
1481
  }
1482
+ /**
1483
+ * Convert asynchronous (promise-based) API to synchronous by wrapping function and method calls in a fiber.
1484
+ * @see https://mol.hyoo.ru/#!section=docs/=1fcpsq_1wh0h2
1485
+ */
1423
1486
  function $mol_wire_sync(obj) {
1424
1487
  return new Proxy(obj, {
1425
1488
  get(obj, field) {
@@ -1600,6 +1663,7 @@ var $;
1600
1663
  "use strict";
1601
1664
  var $;
1602
1665
  (function ($) {
1666
+ /** Decorates solo object channel to [mol_wire_atom](../atom/atom.ts). */
1603
1667
  function $mol_wire_solo(host, field, descr) {
1604
1668
  if (!descr)
1605
1669
  descr = Reflect.getOwnPropertyDescriptor(host, field);
@@ -1639,6 +1703,7 @@ var $;
1639
1703
  var $;
1640
1704
  (function ($_1) {
1641
1705
  $mol_test({
1706
+ // https://github.com/nin-jin/slides/tree/master/reactivity#component-states
1642
1707
  'Cached channel'($) {
1643
1708
  class App extends $mol_object2 {
1644
1709
  static $ = $;
@@ -1696,6 +1761,7 @@ var $;
1696
1761
  $mol_assert_equal(App.value(5), 21);
1697
1762
  $mol_assert_equal(App.value(), 21);
1698
1763
  },
1764
+ // https://github.com/nin-jin/slides/tree/master/reactivity#wish-consistency
1699
1765
  'Auto recalculation of cached values'($) {
1700
1766
  class App extends $mol_object2 {
1701
1767
  static $ = $;
@@ -1723,6 +1789,7 @@ var $;
1723
1789
  App.xxx(5);
1724
1790
  $mol_assert_equal(App.zzz(), 7);
1725
1791
  },
1792
+ // https://github.com/nin-jin/slides/tree/master/reactivity#wish-reasonability
1726
1793
  'Skip recalculation when actually no dependency changes'($) {
1727
1794
  const log = [];
1728
1795
  class App extends $mol_object2 {
@@ -1756,6 +1823,7 @@ var $;
1756
1823
  App.zzz();
1757
1824
  $mol_assert_like(log, ['zzz', 'yyy', 'xxx', 'xxx', 'yyy']);
1758
1825
  },
1826
+ // https://github.com/nin-jin/slides/tree/master/reactivity#flow-auto
1759
1827
  'Flow: Auto'($) {
1760
1828
  class App extends $mol_object2 {
1761
1829
  static get $() { return $; }
@@ -1793,6 +1861,7 @@ var $;
1793
1861
  $mol_assert_equal(App.result(), 23);
1794
1862
  $mol_assert_equal(App.counter, 4);
1795
1863
  },
1864
+ // https://github.com/nin-jin/slides/tree/master/reactivity#dupes-equality
1796
1865
  'Dupes: Equality'($) {
1797
1866
  let counter = 0;
1798
1867
  class App extends $mol_object2 {
@@ -1816,6 +1885,7 @@ var $;
1816
1885
  App.foo({ numbs: [2] });
1817
1886
  $mol_assert_like(App.bar(), { numbs: [2], count: 2 });
1818
1887
  },
1888
+ // https://github.com/nin-jin/slides/tree/master/reactivity#cycle-fail
1819
1889
  'Cycle: Fail'($) {
1820
1890
  class App extends $mol_object2 {
1821
1891
  static $ = $;
@@ -1840,6 +1910,29 @@ var $;
1840
1910
  ], App, "test", null);
1841
1911
  App.test();
1842
1912
  },
1913
+ // https://github.com/nin-jin/slides/tree/master/reactivity#wish-stability
1914
+ // 'Update deps on push'( $ ) {
1915
+ // class App extends $mol_object2 {
1916
+ // static $ = $
1917
+ // @ $mol_wire_solo
1918
+ // static left( next = false ) {
1919
+ // return next
1920
+ // }
1921
+ // @ $mol_wire_solo
1922
+ // static right( next = false ) {
1923
+ // return next
1924
+ // }
1925
+ // @ $mol_wire_solo
1926
+ // static res( next?: boolean ) {
1927
+ // return this.left( next ) && this.right()
1928
+ // }
1929
+ // }
1930
+ // $mol_assert_equal( App.res(), false )
1931
+ // $mol_assert_equal( App.res( true ), false )
1932
+ // $mol_assert_equal( App.right( true ), true )
1933
+ // $mol_assert_equal( App.res(), true )
1934
+ // } ,
1935
+ // https://github.com/nin-jin/slides/tree/master/reactivity#wish-stability
1843
1936
  'Different order of pull and push'($) {
1844
1937
  class App extends $mol_object2 {
1845
1938
  static $ = $;
@@ -1851,7 +1944,7 @@ var $;
1851
1944
  }
1852
1945
  static slow(next) {
1853
1946
  if (next !== undefined)
1854
- this.slow();
1947
+ this.slow(); // enforce pull before push
1855
1948
  return this.store(next);
1856
1949
  }
1857
1950
  }
@@ -1870,6 +1963,7 @@ var $;
1870
1963
  App.store(777);
1871
1964
  $mol_assert_equal(App.fast(), App.slow(), 777);
1872
1965
  },
1966
+ // https://github.com/nin-jin/slides/tree/master/reactivity#wish-stability
1873
1967
  'Actions inside invariant'($) {
1874
1968
  class App extends $mol_object2 {
1875
1969
  static $ = $;
@@ -1909,6 +2003,7 @@ var $;
1909
2003
  static toggle() {
1910
2004
  const prev = this.checked();
1911
2005
  $mol_assert_unique(this.checked(!prev), prev);
2006
+ // $mol_assert_equal( this.checked() , prev )
1912
2007
  }
1913
2008
  static res() {
1914
2009
  return this.checked();
@@ -1933,6 +2028,39 @@ var $;
1933
2028
  ], App, "test", null);
1934
2029
  await $mol_wire_async(App).test();
1935
2030
  },
2031
+ // // https://github.com/nin-jin/slides/tree/master/reactivity#wish-stability
2032
+ // 'Stable order of multiple root'( $ ) {
2033
+ // class App extends $mol_object2 {
2034
+ // static $ = $
2035
+ // static counter = 0
2036
+ // @ $mol_wire_solo
2037
+ // static left_trigger( next = 0 ) {
2038
+ // return next
2039
+ // }
2040
+ // @ $mol_wire_solo
2041
+ // static left_root() {
2042
+ // this.left_trigger()
2043
+ // return ++ this.counter
2044
+ // }
2045
+ // @ $mol_wire_solo
2046
+ // static right_trigger( next = 0 ) {
2047
+ // return next
2048
+ // }
2049
+ // @ $mol_wire_solo
2050
+ // static right_root() {
2051
+ // this.right_trigger()
2052
+ // return ++ this.counter
2053
+ // }
2054
+ // }
2055
+ // $mol_assert_equal( App.left_root(), 1 )
2056
+ // $mol_assert_equal( App.right_root(), 2 )
2057
+ // App.right_trigger( 1 )
2058
+ // App.left_trigger( 1 )
2059
+ // $mol_wire_fiber.sync()
2060
+ // $mol_assert_equal( App.right_root(), 4 )
2061
+ // $mol_assert_equal( App.left_root(), 3 )
2062
+ // } ,
2063
+ // https://github.com/nin-jin/slides/tree/master/reactivity#error-store
1936
2064
  'Restore after error'($) {
1937
2065
  class App extends $mol_object2 {
1938
2066
  static get $() { return $; }
@@ -2030,6 +2158,7 @@ var $;
2030
2158
  App.showing(true);
2031
2159
  $mol_assert_unique(App.render(), details);
2032
2160
  },
2161
+ // https://github.com/nin-jin/slides/tree/master/reactivity#wish-stability
2033
2162
  async 'Hold pubs while wait async task'($) {
2034
2163
  class App extends $mol_object2 {
2035
2164
  static $ = $;
@@ -2106,6 +2235,7 @@ var $;
2106
2235
  "use strict";
2107
2236
  var $;
2108
2237
  (function ($) {
2238
+ /** Reactive memoizing multiplexed property decorator. */
2109
2239
  function $mol_wire_plex(host, field, descr) {
2110
2240
  if (!descr)
2111
2241
  descr = Reflect.getOwnPropertyDescriptor(host, field);
@@ -2259,6 +2389,7 @@ var $;
2259
2389
  "use strict";
2260
2390
  var $;
2261
2391
  (function ($) {
2392
+ /** Run code without state changes */
2262
2393
  function $mol_wire_probe(task, def) {
2263
2394
  const warm = $mol_wire_fiber.warm;
2264
2395
  try {
@@ -2305,7 +2436,25 @@ var $;
2305
2436
  "use strict";
2306
2437
  var $;
2307
2438
  (function ($) {
2439
+ /**
2440
+ * Reactive memoizing solo property decorator from [mol_wire](../wire/README.md)
2441
+ * @example
2442
+ * '@' $mol_mem
2443
+ * name(next?: string) {
2444
+ * return next ?? 'default'
2445
+ * }
2446
+ * @see https://mol.hyoo.ru/#!section=docs/=qxmh6t_sinbmb
2447
+ */
2308
2448
  $.$mol_mem = $mol_wire_solo;
2449
+ /**
2450
+ * Reactive memoizing multiplexed property decorator [mol_wire](../wire/README.md)
2451
+ * @example
2452
+ * '@' $mol_mem_key
2453
+ * name(id: number, next?: string) {
2454
+ * return next ?? 'default'
2455
+ * }
2456
+ * @see https://mol.hyoo.ru/#!section=docs/=qxmh6t_sinbmb
2457
+ */
2309
2458
  $.$mol_mem_key = $mol_wire_plex;
2310
2459
  })($ || ($ = {}));
2311
2460
 
@@ -2313,6 +2462,7 @@ var $;
2313
2462
  "use strict";
2314
2463
  var $;
2315
2464
  (function ($) {
2465
+ /** Watch and logs reactive states. Logger automatically added to test bundle which is adding to `test.html`. */
2316
2466
  class $mol_wire_log extends $mol_object2 {
2317
2467
  static watch(task) {
2318
2468
  return task;