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/web.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,36 @@ 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
+ if (this.sub_empty)
961
+ this.destructor();
962
+ }
963
+ }
964
+ $.$mol_wire_fiber_temp = $mol_wire_fiber_temp;
965
+ })($ || ($ = {}));
966
+ //mol/wire/fiber/temp/temp.ts
967
+ ;
968
+ "use strict";
969
+ var $;
1104
970
  (function ($) {
1105
971
  function $mol_wire_sync(obj) {
1106
972
  return new Proxy(obj, {
@@ -1146,33 +1012,157 @@ var $;
1146
1012
  "use strict";
1147
1013
  var $;
1148
1014
  (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;
1015
+ function $mol_guid(length = 8, exists = () => false) {
1016
+ for (;;) {
1017
+ let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
1018
+ if (exists(id))
1019
+ continue;
1020
+ return id;
1021
+ }
1157
1022
  }
1158
- $.$mol_fail_catch = $mol_fail_catch;
1023
+ $.$mol_guid = $mol_guid;
1159
1024
  })($ || ($ = {}));
1160
- //mol/fail/catch/catch.ts
1025
+ //mol/guid/guid.ts
1161
1026
  ;
1162
1027
  "use strict";
1163
1028
  var $;
1164
1029
  (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;
1030
+ $.$mol_key_store = new WeakMap();
1031
+ function $mol_key(value) {
1032
+ if (!value)
1033
+ return JSON.stringify(value);
1034
+ if (typeof value !== 'object' && typeof value !== 'function')
1035
+ return JSON.stringify(value);
1036
+ return JSON.stringify(value, (field, value) => {
1037
+ if (!value)
1038
+ return value;
1039
+ if (typeof value !== 'object' && typeof value !== 'function')
1040
+ return value;
1041
+ if (Array.isArray(value))
1042
+ return value;
1043
+ const proto = Reflect.getPrototypeOf(value);
1044
+ if (!proto)
1045
+ return value;
1046
+ if (Reflect.getPrototypeOf(proto) === null)
1047
+ return value;
1048
+ if ('toJSON' in value)
1049
+ return value;
1050
+ if (value instanceof RegExp)
1051
+ return value.toString();
1052
+ let key = $.$mol_key_store.get(value);
1053
+ if (key)
1054
+ return key;
1055
+ key = $mol_guid();
1056
+ $.$mol_key_store.set(value, key);
1057
+ return key;
1058
+ });
1059
+ }
1060
+ $.$mol_key = $mol_key;
1061
+ })($ || ($ = {}));
1062
+ //mol/key/key.ts
1063
+ ;
1064
+ "use strict";
1065
+ var $;
1066
+ (function ($) {
1067
+ function $mol_wire_method(host, field, descr) {
1068
+ if (!descr)
1069
+ descr = Reflect.getOwnPropertyDescriptor(host, field);
1070
+ const orig = descr?.value ?? host[field];
1071
+ const sup = Reflect.getPrototypeOf(host);
1072
+ if (typeof sup[field] === 'function') {
1073
+ Object.defineProperty(orig, 'name', { value: sup[field].name });
1074
+ }
1075
+ const temp = $mol_wire_fiber_temp.getter(orig);
1076
+ const value = function (...args) {
1077
+ const fiber = temp(this ?? null, args);
1078
+ return fiber.sync();
1079
+ };
1080
+ Object.defineProperty(value, 'name', { value: orig.name + ' ' });
1081
+ Object.assign(value, { orig });
1082
+ const descr2 = { ...descr, value };
1083
+ Reflect.defineProperty(host, field, descr2);
1084
+ return descr2;
1172
1085
  }
1173
- $.$mol_fail_log = $mol_fail_log;
1086
+ $.$mol_wire_method = $mol_wire_method;
1174
1087
  })($ || ($ = {}));
1175
- //mol/fail/log/log.ts
1088
+ //mol/wire/method/method.ts
1089
+ ;
1090
+ "use strict";
1091
+ var $;
1092
+ (function ($) {
1093
+ class $mol_wire_fiber_persist extends $mol_wire_fiber {
1094
+ static getter(task, keys) {
1095
+ const field = task.name + '()';
1096
+ if (keys) {
1097
+ return function $mol_wire_fiber_persist_get(host, args) {
1098
+ let dict, key, fiber;
1099
+ key = `${host?.[Symbol.toStringTag] ?? host}.${task.name}(${args.map(v => $mol_key(v)).join(',')})`;
1100
+ dict = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
1101
+ if (dict) {
1102
+ const existen = dict.get(key);
1103
+ if (existen)
1104
+ return existen;
1105
+ }
1106
+ else {
1107
+ dict = (host ?? task)[field] = new Map();
1108
+ }
1109
+ fiber = new $mol_wire_fiber_persist(key, task, host, ...args);
1110
+ dict.set(key, fiber);
1111
+ return fiber;
1112
+ };
1113
+ }
1114
+ else {
1115
+ return function $mol_wire_fiber_persist_get(host, args) {
1116
+ const existen = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
1117
+ if (existen)
1118
+ return existen;
1119
+ const key = `${host?.[Symbol.toStringTag] ?? host}.${field}`;
1120
+ const fiber = new $mol_wire_fiber_persist(key, task, host, ...args);
1121
+ (host ?? task)[field] = fiber;
1122
+ return fiber;
1123
+ };
1124
+ }
1125
+ }
1126
+ recall(...args) {
1127
+ if (this.cursor > $mol_wire_cursor.fresh) {
1128
+ try {
1129
+ this.once();
1130
+ }
1131
+ catch (error) {
1132
+ if (error instanceof Promise)
1133
+ $mol_fail_hidden(error);
1134
+ }
1135
+ }
1136
+ return this.put(this.task.call(this.host, ...args));
1137
+ }
1138
+ once() {
1139
+ return this.sync();
1140
+ }
1141
+ destructor() {
1142
+ super.destructor();
1143
+ const prev = this.cache;
1144
+ if ($mol_owning_check(this, prev)) {
1145
+ prev.destructor();
1146
+ }
1147
+ if (this.pub_from === 0) {
1148
+ ;
1149
+ (this.host ?? this.task)[this.field()] = null;
1150
+ }
1151
+ else {
1152
+ ;
1153
+ (this.host ?? this.task)[this.field()].delete(this[Symbol.toStringTag]);
1154
+ }
1155
+ }
1156
+ }
1157
+ __decorate([
1158
+ $mol_wire_method
1159
+ ], $mol_wire_fiber_persist.prototype, "recall", null);
1160
+ __decorate([
1161
+ $mol_wire_method
1162
+ ], $mol_wire_fiber_persist.prototype, "once", null);
1163
+ $.$mol_wire_fiber_persist = $mol_wire_fiber_persist;
1164
+ })($ || ($ = {}));
1165
+ //mol/wire/fiber/persist/persist.ts
1176
1166
  ;
1177
1167
  "use strict";
1178
1168
  var $;
@@ -1201,13 +1191,13 @@ var $;
1201
1191
  const persist = $mol_wire_fiber_persist.getter(func, keys);
1202
1192
  const wrapper = function (...args) {
1203
1193
  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);
1194
+ if (args.length <= keys || args[keys] === undefined) {
1195
+ if ($mol_wire_auto() instanceof $mol_wire_fiber_temp) {
1196
+ return atom.once();
1197
+ }
1198
+ else {
1199
+ return atom.sync();
1200
+ }
1211
1201
  }
1212
1202
  return atom.recall(...args);
1213
1203
  };