mol_wire_lib 1.0.96 → 1.0.99

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