mol_wire_lib 1.0.97 → 1.0.100

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.js CHANGED
@@ -93,7 +93,7 @@ var $;
93
93
  $mol_wire_auto()?.track_next(this);
94
94
  }
95
95
  refresh() { }
96
- commit() { }
96
+ complete() { }
97
97
  emit(quant = $mol_wire_cursor.stale) {
98
98
  for (let i = this.sub_from; i < this.length; i += 2) {
99
99
  ;
@@ -338,14 +338,12 @@ var $;
338
338
  }
339
339
  this.sub_from = this.cursor;
340
340
  }
341
- commit() {
342
- this.commit_pubs();
343
- }
344
- commit_pubs() {
341
+ complete() { }
342
+ complete_pubs() {
345
343
  const limit = this.cursor < 0 ? this.sub_from : this.cursor;
346
344
  for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
347
345
  const pub = this[cursor];
348
- pub?.commit();
346
+ pub?.complete();
349
347
  }
350
348
  }
351
349
  absorb(quant = $mol_wire_cursor.stale) {
@@ -689,84 +687,6 @@ var $;
689
687
  ;
690
688
  "use strict";
691
689
  var $;
692
- (function ($) {
693
- function $mol_guid(length = 8, exists = () => false) {
694
- for (;;) {
695
- let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
696
- if (exists(id))
697
- continue;
698
- return id;
699
- }
700
- }
701
- $.$mol_guid = $mol_guid;
702
- })($ || ($ = {}));
703
- //mol/guid/guid.ts
704
- ;
705
- "use strict";
706
- var $;
707
- (function ($) {
708
- $.$mol_key_store = new WeakMap();
709
- function $mol_key(value) {
710
- if (!value)
711
- return JSON.stringify(value);
712
- if (typeof value !== 'object' && typeof value !== 'function')
713
- return JSON.stringify(value);
714
- return JSON.stringify(value, (field, value) => {
715
- if (!value)
716
- return value;
717
- if (typeof value !== 'object' && typeof value !== 'function')
718
- return value;
719
- if (Array.isArray(value))
720
- return value;
721
- const proto = Reflect.getPrototypeOf(value);
722
- if (!proto)
723
- return value;
724
- if (Reflect.getPrototypeOf(proto) === null)
725
- return value;
726
- if ('toJSON' in value)
727
- return value;
728
- if (value instanceof RegExp)
729
- return value.toString();
730
- let key = $.$mol_key_store.get(value);
731
- if (key)
732
- return key;
733
- key = $mol_guid();
734
- $.$mol_key_store.set(value, key);
735
- return key;
736
- });
737
- }
738
- $.$mol_key = $mol_key;
739
- })($ || ($ = {}));
740
- //mol/key/key.ts
741
- ;
742
- "use strict";
743
- var $;
744
- (function ($) {
745
- function $mol_wire_method(host, field, descr) {
746
- if (!descr)
747
- descr = Reflect.getOwnPropertyDescriptor(host, field);
748
- const orig = descr?.value ?? host[field];
749
- const sup = Reflect.getPrototypeOf(host);
750
- if (typeof sup[field] === 'function') {
751
- Object.defineProperty(orig, 'name', { value: sup[field].name });
752
- }
753
- const temp = $mol_wire_fiber_temp.getter(orig);
754
- const value = function (...args) {
755
- const fiber = temp(this ?? null, args);
756
- return fiber.sync();
757
- };
758
- Object.defineProperty(value, 'name', { value: orig.name + ' ' });
759
- Object.assign(value, { orig });
760
- const descr2 = { ...descr, value };
761
- Reflect.defineProperty(host, field, descr2);
762
- return descr2;
763
- }
764
- $.$mol_wire_method = $mol_wire_method;
765
- })($ || ($ = {}));
766
- //mol/wire/method/method.ts
767
- ;
768
- "use strict";
769
- var $;
770
690
  (function ($) {
771
691
  const handled = new WeakSet();
772
692
  class $mol_wire_fiber extends $mol_wire_pub_sub {
@@ -941,15 +861,12 @@ var $;
941
861
  if (next instanceof Promise)
942
862
  return next;
943
863
  if (this instanceof $mol_wire_fiber_persist) {
944
- this.commit_pubs();
864
+ this.complete_pubs();
945
865
  }
946
866
  else {
947
- if (this.sub_empty) {
948
- this.commit();
949
- }
950
- else {
951
- this.commit_pubs();
952
- }
867
+ this.cursor = $mol_wire_cursor.final;
868
+ if (this.sub_empty)
869
+ this.destructor();
953
870
  }
954
871
  return next;
955
872
  }
@@ -983,87 +900,6 @@ var $;
983
900
  }
984
901
  }
985
902
  $.$mol_wire_fiber = $mol_wire_fiber;
986
- class $mol_wire_fiber_temp extends $mol_wire_fiber {
987
- static getter(task) {
988
- return function $mol_wire_fiber_temp_get(host, args) {
989
- const existen = $mol_wire_auto()?.track_next();
990
- reuse: if (existen) {
991
- if (!(existen instanceof $mol_wire_fiber_temp))
992
- break reuse;
993
- if (existen.host !== host)
994
- break reuse;
995
- if (existen.task !== task)
996
- break reuse;
997
- if (!$mol_compare_deep(existen.args, args))
998
- break reuse;
999
- return existen;
1000
- }
1001
- return new $mol_wire_fiber_temp(`${host?.[Symbol.toStringTag] ?? host}.${task.name}(#)`, task, host, ...args);
1002
- };
1003
- }
1004
- commit() {
1005
- super.commit();
1006
- this.destructor();
1007
- }
1008
- }
1009
- $.$mol_wire_fiber_temp = $mol_wire_fiber_temp;
1010
- class $mol_wire_fiber_persist extends $mol_wire_fiber {
1011
- static getter(task, keys) {
1012
- const field = task.name + '()';
1013
- if (keys) {
1014
- return function $mol_wire_fiber_persist_get(host, args) {
1015
- let dict, key, fiber;
1016
- key = `${host?.[Symbol.toStringTag] ?? host}.${task.name}(${args.map(v => $mol_key(v)).join(',')})`;
1017
- dict = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
1018
- if (dict) {
1019
- const existen = dict.get(key);
1020
- if (existen)
1021
- return existen;
1022
- }
1023
- else {
1024
- dict = (host ?? task)[field] = new Map();
1025
- }
1026
- fiber = new $mol_wire_fiber_persist(key, task, host, ...args);
1027
- dict.set(key, fiber);
1028
- return fiber;
1029
- };
1030
- }
1031
- else {
1032
- return function $mol_wire_fiber_persist_get(host, args) {
1033
- const existen = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
1034
- if (existen)
1035
- return existen;
1036
- const key = `${host?.[Symbol.toStringTag] ?? host}.${field}`;
1037
- const fiber = new $mol_wire_fiber_persist(key, task, host, ...args);
1038
- (host ?? task)[field] = fiber;
1039
- return fiber;
1040
- };
1041
- }
1042
- }
1043
- recall(...args) {
1044
- return this.put(this.task.call(this.host, ...args));
1045
- }
1046
- commit() { }
1047
- destructor() {
1048
- super.destructor();
1049
- const prev = this.cache;
1050
- if ($mol_owning_check(this, prev)) {
1051
- prev.destructor();
1052
- }
1053
- if (this.pub_from === 0) {
1054
- ;
1055
- (this.host ?? this.task)[this.field()] = null;
1056
- }
1057
- else {
1058
- ;
1059
- (this.host ?? this.task)[this.field()].delete(this[Symbol.toStringTag]);
1060
- }
1061
- }
1062
- }
1063
- __decorate([
1064
- $mol_wire_method
1065
- ], $mol_wire_fiber_persist.prototype, "recall", null);
1066
- $.$mol_wire_fiber_persist = $mol_wire_fiber_persist;
1067
903
  })($ || ($ = {}));
1068
904
  //mol/wire/fiber/fiber.ts
1069
905
  ;
@@ -1097,6 +933,36 @@ var $;
1097
933
  ;
1098
934
  "use strict";
1099
935
  var $;
936
+ (function ($) {
937
+ class $mol_wire_fiber_temp extends $mol_wire_fiber {
938
+ static getter(task) {
939
+ return function $mol_wire_fiber_temp_get(host, args) {
940
+ const existen = $mol_wire_auto()?.track_next();
941
+ reuse: if (existen) {
942
+ if (!(existen instanceof $mol_wire_fiber_temp))
943
+ break reuse;
944
+ if (existen.host !== host)
945
+ break reuse;
946
+ if (existen.task !== task)
947
+ break reuse;
948
+ if (!$mol_compare_deep(existen.args, args))
949
+ break reuse;
950
+ return existen;
951
+ }
952
+ return new $mol_wire_fiber_temp(`${host?.[Symbol.toStringTag] ?? host}.${task.name}(#)`, task, host, ...args);
953
+ };
954
+ }
955
+ complete() {
956
+ if (this.sub_empty)
957
+ this.destructor();
958
+ }
959
+ }
960
+ $.$mol_wire_fiber_temp = $mol_wire_fiber_temp;
961
+ })($ || ($ = {}));
962
+ //mol/wire/fiber/temp/temp.ts
963
+ ;
964
+ "use strict";
965
+ var $;
1100
966
  (function ($) {
1101
967
  function $mol_wire_sync(obj) {
1102
968
  return new Proxy(obj, {
@@ -1142,33 +1008,157 @@ var $;
1142
1008
  "use strict";
1143
1009
  var $;
1144
1010
  (function ($) {
1145
- const cacthed = new WeakMap();
1146
- function $mol_fail_catch(error) {
1147
- if (typeof error !== 'object')
1148
- return false;
1149
- if (cacthed.get(error))
1150
- return false;
1151
- cacthed.set(error, true);
1152
- return true;
1011
+ function $mol_guid(length = 8, exists = () => false) {
1012
+ for (;;) {
1013
+ let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
1014
+ if (exists(id))
1015
+ continue;
1016
+ return id;
1017
+ }
1153
1018
  }
1154
- $.$mol_fail_catch = $mol_fail_catch;
1019
+ $.$mol_guid = $mol_guid;
1155
1020
  })($ || ($ = {}));
1156
- //mol/fail/catch/catch.ts
1021
+ //mol/guid/guid.ts
1157
1022
  ;
1158
1023
  "use strict";
1159
1024
  var $;
1160
1025
  (function ($) {
1161
- function $mol_fail_log(error) {
1162
- if (error instanceof Promise)
1163
- return false;
1164
- if (!$mol_fail_catch(error))
1165
- return false;
1166
- console.error(error);
1167
- return true;
1026
+ $.$mol_key_store = new WeakMap();
1027
+ function $mol_key(value) {
1028
+ if (!value)
1029
+ return JSON.stringify(value);
1030
+ if (typeof value !== 'object' && typeof value !== 'function')
1031
+ return JSON.stringify(value);
1032
+ return JSON.stringify(value, (field, value) => {
1033
+ if (!value)
1034
+ return value;
1035
+ if (typeof value !== 'object' && typeof value !== 'function')
1036
+ return value;
1037
+ if (Array.isArray(value))
1038
+ return value;
1039
+ const proto = Reflect.getPrototypeOf(value);
1040
+ if (!proto)
1041
+ return value;
1042
+ if (Reflect.getPrototypeOf(proto) === null)
1043
+ return value;
1044
+ if ('toJSON' in value)
1045
+ return value;
1046
+ if (value instanceof RegExp)
1047
+ return value.toString();
1048
+ let key = $.$mol_key_store.get(value);
1049
+ if (key)
1050
+ return key;
1051
+ key = $mol_guid();
1052
+ $.$mol_key_store.set(value, key);
1053
+ return key;
1054
+ });
1055
+ }
1056
+ $.$mol_key = $mol_key;
1057
+ })($ || ($ = {}));
1058
+ //mol/key/key.ts
1059
+ ;
1060
+ "use strict";
1061
+ var $;
1062
+ (function ($) {
1063
+ function $mol_wire_method(host, field, descr) {
1064
+ if (!descr)
1065
+ descr = Reflect.getOwnPropertyDescriptor(host, field);
1066
+ const orig = descr?.value ?? host[field];
1067
+ const sup = Reflect.getPrototypeOf(host);
1068
+ if (typeof sup[field] === 'function') {
1069
+ Object.defineProperty(orig, 'name', { value: sup[field].name });
1070
+ }
1071
+ const temp = $mol_wire_fiber_temp.getter(orig);
1072
+ const value = function (...args) {
1073
+ const fiber = temp(this ?? null, args);
1074
+ return fiber.sync();
1075
+ };
1076
+ Object.defineProperty(value, 'name', { value: orig.name + ' ' });
1077
+ Object.assign(value, { orig });
1078
+ const descr2 = { ...descr, value };
1079
+ Reflect.defineProperty(host, field, descr2);
1080
+ return descr2;
1168
1081
  }
1169
- $.$mol_fail_log = $mol_fail_log;
1082
+ $.$mol_wire_method = $mol_wire_method;
1170
1083
  })($ || ($ = {}));
1171
- //mol/fail/log/log.ts
1084
+ //mol/wire/method/method.ts
1085
+ ;
1086
+ "use strict";
1087
+ var $;
1088
+ (function ($) {
1089
+ class $mol_wire_fiber_persist extends $mol_wire_fiber {
1090
+ static getter(task, keys) {
1091
+ const field = task.name + '()';
1092
+ if (keys) {
1093
+ return function $mol_wire_fiber_persist_get(host, args) {
1094
+ let dict, key, fiber;
1095
+ key = `${host?.[Symbol.toStringTag] ?? host}.${task.name}(${args.map(v => $mol_key(v)).join(',')})`;
1096
+ dict = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
1097
+ if (dict) {
1098
+ const existen = dict.get(key);
1099
+ if (existen)
1100
+ return existen;
1101
+ }
1102
+ else {
1103
+ dict = (host ?? task)[field] = new Map();
1104
+ }
1105
+ fiber = new $mol_wire_fiber_persist(key, task, host, ...args);
1106
+ dict.set(key, fiber);
1107
+ return fiber;
1108
+ };
1109
+ }
1110
+ else {
1111
+ return function $mol_wire_fiber_persist_get(host, args) {
1112
+ const existen = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
1113
+ if (existen)
1114
+ return existen;
1115
+ const key = `${host?.[Symbol.toStringTag] ?? host}.${field}`;
1116
+ const fiber = new $mol_wire_fiber_persist(key, task, host, ...args);
1117
+ (host ?? task)[field] = fiber;
1118
+ return fiber;
1119
+ };
1120
+ }
1121
+ }
1122
+ recall(...args) {
1123
+ if (this.cursor > $mol_wire_cursor.fresh) {
1124
+ try {
1125
+ this.once();
1126
+ }
1127
+ catch (error) {
1128
+ if (error instanceof Promise)
1129
+ $mol_fail_hidden(error);
1130
+ }
1131
+ }
1132
+ return this.put(this.task.call(this.host, ...args));
1133
+ }
1134
+ once() {
1135
+ return this.sync();
1136
+ }
1137
+ destructor() {
1138
+ super.destructor();
1139
+ const prev = this.cache;
1140
+ if ($mol_owning_check(this, prev)) {
1141
+ prev.destructor();
1142
+ }
1143
+ if (this.pub_from === 0) {
1144
+ ;
1145
+ (this.host ?? this.task)[this.field()] = null;
1146
+ }
1147
+ else {
1148
+ ;
1149
+ (this.host ?? this.task)[this.field()].delete(this[Symbol.toStringTag]);
1150
+ }
1151
+ }
1152
+ }
1153
+ __decorate([
1154
+ $mol_wire_method
1155
+ ], $mol_wire_fiber_persist.prototype, "recall", null);
1156
+ __decorate([
1157
+ $mol_wire_method
1158
+ ], $mol_wire_fiber_persist.prototype, "once", null);
1159
+ $.$mol_wire_fiber_persist = $mol_wire_fiber_persist;
1160
+ })($ || ($ = {}));
1161
+ //mol/wire/fiber/persist/persist.ts
1172
1162
  ;
1173
1163
  "use strict";
1174
1164
  var $;
@@ -1197,13 +1187,13 @@ var $;
1197
1187
  const persist = $mol_wire_fiber_persist.getter(func, keys);
1198
1188
  const wrapper = function (...args) {
1199
1189
  let atom = persist(this, args.slice(0, keys));
1200
- if (args.length <= keys || args[keys] === undefined)
1201
- return atom.sync();
1202
- try {
1203
- atom.sync();
1204
- }
1205
- catch (error) {
1206
- $mol_fail_log(error);
1190
+ if (args.length <= keys || args[keys] === undefined) {
1191
+ if ($mol_wire_auto() instanceof $mol_wire_fiber_temp) {
1192
+ return atom.once();
1193
+ }
1194
+ else {
1195
+ return atom.sync();
1196
+ }
1207
1197
  }
1208
1198
  return atom.recall(...args);
1209
1199
  };