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