mol_wire_lib 1.0.27 → 1.0.31

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/node.test.js CHANGED
@@ -89,7 +89,7 @@ var $;
89
89
  this.reap();
90
90
  }
91
91
  reap() { }
92
- track_promote() {
92
+ promote() {
93
93
  $mol_wire_auto?.track_next(this);
94
94
  }
95
95
  up() { }
@@ -250,7 +250,8 @@ var $;
250
250
  cursor = $mol_wire_cursor.stale;
251
251
  get pub_list() {
252
252
  const res = [];
253
- for (let i = this.pub_from; i < this.sub_from; i += 2) {
253
+ const max = this.cursor >= 0 ? this.cursor : this.sub_from;
254
+ for (let i = this.pub_from; i < max; i += 2) {
254
255
  res.push(this[i]);
255
256
  }
256
257
  return res;
@@ -261,11 +262,11 @@ var $;
261
262
  $mol_wire_auto = this;
262
263
  return sub;
263
264
  }
264
- track_promote() {
265
+ promote() {
265
266
  if (this.cursor >= this.pub_from) {
266
267
  $mol_fail(new Error('Circular subscription'));
267
268
  }
268
- super.track_promote();
269
+ super.promote();
269
270
  }
270
271
  track_next(pub) {
271
272
  if (this.cursor < 0)
@@ -869,10 +870,11 @@ var $;
869
870
  return this.task.name + '()';
870
871
  }
871
872
  constructor(host, task, id, ...args) {
872
- super(...args, undefined);
873
+ super(...args, undefined, undefined);
873
874
  this.host = host;
874
875
  this.task = task;
875
876
  this.pop();
877
+ this.pop();
876
878
  this.pub_from = this.sub_from = args.length;
877
879
  this[Symbol.toStringTag] = id;
878
880
  }
@@ -904,6 +906,9 @@ var $;
904
906
  toString() {
905
907
  return this[Symbol.toStringTag];
906
908
  }
909
+ toJSON() {
910
+ return this[Symbol.toStringTag];
911
+ }
907
912
  [$mol_dev_format_head]() {
908
913
  return $mol_dev_format_div({}, $mol_dev_format_native(this), $mol_dev_format_shade(this.cursor.toString() + ' '), $mol_dev_format_auto(this.cache));
909
914
  }
@@ -1014,7 +1019,7 @@ var $;
1014
1019
  if (!$mol_wire_fiber.warm) {
1015
1020
  return this.result;
1016
1021
  }
1017
- this.track_promote();
1022
+ this.promote();
1018
1023
  this.up();
1019
1024
  if (this.cache instanceof Error) {
1020
1025
  return $mol_fail_hidden(this.cache);
@@ -1239,6 +1244,43 @@ var $;
1239
1244
  ;
1240
1245
  "use strict";
1241
1246
  var $;
1247
+ (function ($) {
1248
+ function $mol_promise() {
1249
+ let done;
1250
+ let fail;
1251
+ const promise = new Promise((d, f) => {
1252
+ done = d;
1253
+ fail = f;
1254
+ });
1255
+ return Object.assign(promise, {
1256
+ done,
1257
+ fail,
1258
+ });
1259
+ }
1260
+ $.$mol_promise = $mol_promise;
1261
+ })($ || ($ = {}));
1262
+ //mol/promise/promise.ts
1263
+ ;
1264
+ "use strict";
1265
+ var $;
1266
+ (function ($) {
1267
+ function $mol_wait_timeout_async(timeout) {
1268
+ const promise = $mol_promise();
1269
+ const task = new this.$mol_after_timeout(timeout, () => promise.done());
1270
+ return Object.assign(promise, {
1271
+ destructor: () => task.destructor()
1272
+ });
1273
+ }
1274
+ $.$mol_wait_timeout_async = $mol_wait_timeout_async;
1275
+ function $mol_wait_timeout(timeout) {
1276
+ return this.$mol_wire_sync(this).$mol_wait_timeout_async(timeout);
1277
+ }
1278
+ $.$mol_wait_timeout = $mol_wait_timeout;
1279
+ })($ || ($ = {}));
1280
+ //mol/wait/timeout/timeout.ts
1281
+ ;
1282
+ "use strict";
1283
+ var $;
1242
1284
  (function ($) {
1243
1285
  function $mol_test_complete() {
1244
1286
  process.exit(0);
@@ -1845,64 +1887,6 @@ var $;
1845
1887
  ;
1846
1888
  "use strict";
1847
1889
  var $;
1848
- (function ($_1) {
1849
- $mol_test({
1850
- 'Collect deps'() {
1851
- const pub1 = new $mol_wire_pub;
1852
- const pub2 = new $mol_wire_pub;
1853
- const sub = new $mol_wire_pub_sub;
1854
- const bu1 = sub.track_on();
1855
- try {
1856
- pub1.track_promote();
1857
- pub2.track_promote();
1858
- pub2.track_promote();
1859
- }
1860
- finally {
1861
- sub.track_cut();
1862
- sub.track_off(bu1);
1863
- }
1864
- pub1.emit();
1865
- pub2.emit();
1866
- $mol_assert_like(sub.pub_list, [pub1, pub2, pub2]);
1867
- const bu2 = sub.track_on();
1868
- try {
1869
- pub1.track_promote();
1870
- pub1.track_promote();
1871
- pub2.track_promote();
1872
- }
1873
- finally {
1874
- sub.track_cut();
1875
- sub.track_off(bu2);
1876
- }
1877
- pub1.emit();
1878
- pub2.emit();
1879
- $mol_assert_like(sub.pub_list, [pub1, pub1, pub2]);
1880
- },
1881
- 'cyclic detection'($) {
1882
- const sub1 = new $mol_wire_pub_sub;
1883
- const sub2 = new $mol_wire_pub_sub;
1884
- const bu1 = sub1.track_on();
1885
- try {
1886
- const bu2 = sub2.track_on();
1887
- try {
1888
- $mol_assert_fail(() => sub1.track_promote(), 'Circular subscription');
1889
- }
1890
- finally {
1891
- sub2.track_cut();
1892
- sub2.track_off(bu2);
1893
- }
1894
- }
1895
- finally {
1896
- sub1.track_cut();
1897
- sub1.track_off(bu1);
1898
- }
1899
- },
1900
- });
1901
- })($ || ($ = {}));
1902
- //mol/wire/pub/sub/sub.test.ts
1903
- ;
1904
- "use strict";
1905
- var $;
1906
1890
  (function ($) {
1907
1891
  $mol_test({
1908
1892
  'get'() {
@@ -1969,25 +1953,6 @@ var $;
1969
1953
  ;
1970
1954
  "use strict";
1971
1955
  var $;
1972
- (function ($) {
1973
- function $mol_promise() {
1974
- let done;
1975
- let fail;
1976
- const promise = new Promise((d, f) => {
1977
- done = d;
1978
- fail = f;
1979
- });
1980
- return Object.assign(promise, {
1981
- done,
1982
- fail,
1983
- });
1984
- }
1985
- $.$mol_promise = $mol_promise;
1986
- })($ || ($ = {}));
1987
- //mol/promise/promise.ts
1988
- ;
1989
- "use strict";
1990
- var $;
1991
1956
  (function ($) {
1992
1957
  $.$mol_after_mock_queue = [];
1993
1958
  function $mol_after_mock_warp() {
@@ -2035,24 +2000,6 @@ var $;
2035
2000
  ;
2036
2001
  "use strict";
2037
2002
  var $;
2038
- (function ($) {
2039
- function $mol_wait_timeout_async(timeout) {
2040
- const promise = $mol_promise();
2041
- const task = new this.$mol_after_timeout(timeout, () => promise.done());
2042
- return Object.assign(promise, {
2043
- destructor: () => task.destructor()
2044
- });
2045
- }
2046
- $.$mol_wait_timeout_async = $mol_wait_timeout_async;
2047
- function $mol_wait_timeout(timeout) {
2048
- return this.$mol_wire_sync(this).$mol_wait_timeout_async(timeout);
2049
- }
2050
- $.$mol_wait_timeout = $mol_wait_timeout;
2051
- })($ || ($ = {}));
2052
- //mol/wait/timeout/timeout.ts
2053
- ;
2054
- "use strict";
2055
- var $;
2056
2003
  (function ($_1) {
2057
2004
  $mol_test({
2058
2005
  async 'Latest Calls Wins on Concurrency'($) {
@@ -2080,6 +2027,64 @@ var $;
2080
2027
  ;
2081
2028
  "use strict";
2082
2029
  var $;
2030
+ (function ($_1) {
2031
+ $mol_test({
2032
+ 'Collect deps'() {
2033
+ const pub1 = new $mol_wire_pub;
2034
+ const pub2 = new $mol_wire_pub;
2035
+ const sub = new $mol_wire_pub_sub;
2036
+ const bu1 = sub.track_on();
2037
+ try {
2038
+ pub1.promote();
2039
+ pub2.promote();
2040
+ pub2.promote();
2041
+ }
2042
+ finally {
2043
+ sub.track_cut();
2044
+ sub.track_off(bu1);
2045
+ }
2046
+ pub1.emit();
2047
+ pub2.emit();
2048
+ $mol_assert_like(sub.pub_list, [pub1, pub2, pub2]);
2049
+ const bu2 = sub.track_on();
2050
+ try {
2051
+ pub1.promote();
2052
+ pub1.promote();
2053
+ pub2.promote();
2054
+ }
2055
+ finally {
2056
+ sub.track_cut();
2057
+ sub.track_off(bu2);
2058
+ }
2059
+ pub1.emit();
2060
+ pub2.emit();
2061
+ $mol_assert_like(sub.pub_list, [pub1, pub1, pub2]);
2062
+ },
2063
+ 'cyclic detection'($) {
2064
+ const sub1 = new $mol_wire_pub_sub;
2065
+ const sub2 = new $mol_wire_pub_sub;
2066
+ const bu1 = sub1.track_on();
2067
+ try {
2068
+ const bu2 = sub2.track_on();
2069
+ try {
2070
+ $mol_assert_fail(() => sub1.promote(), 'Circular subscription');
2071
+ }
2072
+ finally {
2073
+ sub2.track_cut();
2074
+ sub2.track_off(bu2);
2075
+ }
2076
+ }
2077
+ finally {
2078
+ sub1.track_cut();
2079
+ sub1.track_off(bu1);
2080
+ }
2081
+ },
2082
+ });
2083
+ })($ || ($ = {}));
2084
+ //mol/wire/pub/sub/sub.test.ts
2085
+ ;
2086
+ "use strict";
2087
+ var $;
2083
2088
  (function ($) {
2084
2089
  $mol_test({
2085
2090
  'Primitives'() {
@@ -2827,50 +2832,12 @@ var $;
2827
2832
  "use strict";
2828
2833
  var $;
2829
2834
  (function ($) {
2830
- $mol_test({
2831
- 'const returns stored value'() {
2832
- const foo = { bar: $mol_const(Math.random()) };
2833
- $mol_assert_equal(foo.bar(), foo.bar());
2834
- $mol_assert_equal(foo.bar(), foo.bar['()']);
2835
- },
2836
- });
2837
- })($ || ($ = {}));
2838
- //mol/const/const.test.ts
2839
- ;
2840
- "use strict";
2841
- var $;
2842
- (function ($_1) {
2843
- $mol_test({
2844
- 'Cached field'($) {
2845
- class App extends $mol_object2 {
2846
- static $ = $;
2847
- static low = 1;
2848
- static get high() {
2849
- return this.low + 1;
2850
- }
2851
- static set high(next) {
2852
- this.low = next - 1;
2853
- }
2854
- static test() {
2855
- $mol_assert_equal(App.high, 2);
2856
- App.high = 3;
2857
- $mol_assert_equal(App.high, 3);
2858
- }
2859
- }
2860
- __decorate([
2861
- $mol_wire_field
2862
- ], App, "low", void 0);
2863
- __decorate([
2864
- $mol_wire_field
2865
- ], App, "high", null);
2866
- __decorate([
2867
- $mol_wire_method
2868
- ], App, "test", null);
2869
- App.test();
2870
- },
2871
- });
2835
+ $.$mol_mem = $mol_wire_mem(0);
2836
+ $.$mol_mem_key = $mol_wire_mem(1);
2837
+ $.$mol_mem_key2 = $mol_wire_mem(2);
2838
+ $.$mol_mem_key3 = $mol_wire_mem(3);
2872
2839
  })($ || ($ = {}));
2873
- //mol/wire/field/field.test.ts
2840
+ //mol/mem/mem.ts
2874
2841
  ;
2875
2842
  "use strict";
2876
2843
  var $;
@@ -2940,6 +2907,115 @@ var $;
2940
2907
  ;
2941
2908
  "use strict";
2942
2909
  var $;
2910
+ (function ($) {
2911
+ class $mol_wire_log extends $mol_object2 {
2912
+ static watch(task) {
2913
+ return task;
2914
+ }
2915
+ static track(fiber) {
2916
+ const prev = $mol_wire_probe(() => this.track(fiber));
2917
+ let next;
2918
+ try {
2919
+ next = fiber.sync();
2920
+ }
2921
+ finally {
2922
+ for (const pub of fiber.pub_list) {
2923
+ if (pub instanceof $mol_wire_fiber) {
2924
+ this.track(pub);
2925
+ }
2926
+ }
2927
+ }
2928
+ if (prev !== undefined && !$mol_compare_deep(prev, next)) {
2929
+ this.$.$mol_log3_rise({
2930
+ message: 'Changed',
2931
+ place: fiber,
2932
+ });
2933
+ }
2934
+ return next;
2935
+ }
2936
+ static active() {
2937
+ try {
2938
+ this.watch()?.();
2939
+ }
2940
+ finally {
2941
+ for (const pub of $mol_wire_auto.pub_list) {
2942
+ if (pub instanceof $mol_wire_fiber) {
2943
+ this.track(pub);
2944
+ }
2945
+ }
2946
+ }
2947
+ }
2948
+ }
2949
+ __decorate([
2950
+ $mol_mem
2951
+ ], $mol_wire_log, "watch", null);
2952
+ __decorate([
2953
+ $mol_mem_key
2954
+ ], $mol_wire_log, "track", null);
2955
+ __decorate([
2956
+ $mol_mem
2957
+ ], $mol_wire_log, "active", null);
2958
+ $.$mol_wire_log = $mol_wire_log;
2959
+ })($ || ($ = {}));
2960
+ //mol/wire/log/log.ts
2961
+ ;
2962
+ "use strict";
2963
+ var $;
2964
+ (function ($) {
2965
+ $mol_wire_log.active();
2966
+ })($ || ($ = {}));
2967
+ //mol/wire/wire.test.ts
2968
+ ;
2969
+ "use strict";
2970
+ var $;
2971
+ (function ($) {
2972
+ $mol_test({
2973
+ 'const returns stored value'() {
2974
+ const foo = { bar: $mol_const(Math.random()) };
2975
+ $mol_assert_equal(foo.bar(), foo.bar());
2976
+ $mol_assert_equal(foo.bar(), foo.bar['()']);
2977
+ },
2978
+ });
2979
+ })($ || ($ = {}));
2980
+ //mol/const/const.test.ts
2981
+ ;
2982
+ "use strict";
2983
+ var $;
2984
+ (function ($_1) {
2985
+ $mol_test({
2986
+ 'Cached field'($) {
2987
+ class App extends $mol_object2 {
2988
+ static $ = $;
2989
+ static low = 1;
2990
+ static get high() {
2991
+ return this.low + 1;
2992
+ }
2993
+ static set high(next) {
2994
+ this.low = next - 1;
2995
+ }
2996
+ static test() {
2997
+ $mol_assert_equal(App.high, 2);
2998
+ App.high = 3;
2999
+ $mol_assert_equal(App.high, 3);
3000
+ }
3001
+ }
3002
+ __decorate([
3003
+ $mol_wire_field
3004
+ ], App, "low", void 0);
3005
+ __decorate([
3006
+ $mol_wire_field
3007
+ ], App, "high", null);
3008
+ __decorate([
3009
+ $mol_wire_method
3010
+ ], App, "test", null);
3011
+ App.test();
3012
+ },
3013
+ });
3014
+ })($ || ($ = {}));
3015
+ //mol/wire/field/field.test.ts
3016
+ ;
3017
+ "use strict";
3018
+ var $;
2943
3019
  (function ($) {
2944
3020
  function $mol_env() {
2945
3021
  return {};