mol_wire_lib 1.0.101 → 1.0.104

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.esm.js CHANGED
@@ -562,131 +562,6 @@ var $;
562
562
  ;
563
563
  "use strict";
564
564
  var $;
565
- (function ($) {
566
- $.$mol_compare_deep_cache = new WeakMap();
567
- function $mol_compare_deep(left, right) {
568
- if (Object.is(left, right))
569
- return true;
570
- if (left === null)
571
- return false;
572
- if (right === null)
573
- return false;
574
- if (typeof left !== 'object')
575
- return false;
576
- if (typeof right !== 'object')
577
- return false;
578
- const left_proto = Reflect.getPrototypeOf(left);
579
- const right_proto = Reflect.getPrototypeOf(right);
580
- if (left_proto !== right_proto)
581
- return false;
582
- if (left instanceof Boolean)
583
- return Object.is(left.valueOf(), right['valueOf']());
584
- if (left instanceof Number)
585
- return Object.is(left.valueOf(), right['valueOf']());
586
- if (left instanceof String)
587
- return Object.is(left.valueOf(), right['valueOf']());
588
- if (left instanceof Date)
589
- return Object.is(left.valueOf(), right['valueOf']());
590
- if (left instanceof RegExp)
591
- return left.source === right['source'] && left.flags === right['flags'];
592
- let left_cache = $.$mol_compare_deep_cache.get(left);
593
- if (left_cache) {
594
- const right_cache = left_cache.get(right);
595
- if (typeof right_cache === 'boolean')
596
- return right_cache;
597
- }
598
- else {
599
- left_cache = new WeakMap([[right, true]]);
600
- $.$mol_compare_deep_cache.set(left, left_cache);
601
- }
602
- let result;
603
- try {
604
- if (left_proto && !Reflect.getPrototypeOf(left_proto))
605
- result = compare_pojo(left, right);
606
- else if (Array.isArray(left))
607
- result = compare_array(left, right);
608
- else if (left instanceof Set)
609
- result = compare_set(left, right);
610
- else if (left instanceof Map)
611
- result = compare_map(left, right);
612
- else if (left instanceof Error)
613
- result = left.stack === right.stack;
614
- else if (ArrayBuffer.isView(left))
615
- result = compare_buffer(left, right);
616
- else if (Symbol.toPrimitive in left)
617
- result = compare_primitive(left, right);
618
- else
619
- result = false;
620
- }
621
- finally {
622
- left_cache.set(right, result);
623
- }
624
- return result;
625
- }
626
- $.$mol_compare_deep = $mol_compare_deep;
627
- function compare_array(left, right) {
628
- const len = left.length;
629
- if (len !== right.length)
630
- return false;
631
- for (let i = 0; i < len; ++i) {
632
- if (!$mol_compare_deep(left[i], right[i]))
633
- return false;
634
- }
635
- return true;
636
- }
637
- function compare_buffer(left, right) {
638
- const len = left.byteLength;
639
- if (len !== right.byteLength)
640
- return false;
641
- for (let i = 0; i < len; ++i) {
642
- if (left[i] !== right[i])
643
- return false;
644
- }
645
- return true;
646
- }
647
- function compare_iterator(left, right, compare) {
648
- while (true) {
649
- const left_next = left.next();
650
- const right_next = right.next();
651
- if (left_next.done !== right_next.done)
652
- return false;
653
- if (left_next.done)
654
- break;
655
- if (!compare(left_next.value, right_next.value))
656
- return false;
657
- }
658
- return true;
659
- }
660
- function compare_set(left, right) {
661
- if (left.size !== right.size)
662
- return false;
663
- return compare_iterator(left.values(), right.values(), $mol_compare_deep);
664
- }
665
- function compare_map(left, right) {
666
- if (left.size !== right.size)
667
- return false;
668
- return compare_iterator(left.keys(), right.keys(), Object.is)
669
- && compare_iterator(left.values(), right.values(), $mol_compare_deep);
670
- }
671
- function compare_pojo(left, right) {
672
- const left_keys = Object.getOwnPropertyNames(left);
673
- const right_keys = Object.getOwnPropertyNames(right);
674
- if (left_keys.length !== right_keys.length)
675
- return false;
676
- for (let key of left_keys) {
677
- if (!$mol_compare_deep(left[key], Reflect.get(right, key)))
678
- return false;
679
- }
680
- return true;
681
- }
682
- function compare_primitive(left, right) {
683
- return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
684
- }
685
- })($ || ($ = {}));
686
- //mol/compare/deep/deep.ts
687
- ;
688
- "use strict";
689
- var $;
690
565
  (function ($) {
691
566
  const handled = new WeakSet();
692
567
  class $mol_wire_fiber extends $mol_wire_pub_sub {
@@ -838,38 +713,6 @@ var $;
838
713
  this.track_off(bu);
839
714
  this.put(result);
840
715
  }
841
- put(next) {
842
- const prev = this.cache;
843
- if (next !== prev) {
844
- if ($mol_owning_check(this, prev)) {
845
- prev.destructor();
846
- }
847
- this.cache = next;
848
- if (this instanceof $mol_wire_fiber_persist && $mol_owning_catch(this, next)) {
849
- try {
850
- next[Symbol.toStringTag] = this[Symbol.toStringTag];
851
- }
852
- catch { }
853
- }
854
- if (this.sub_from < this.length) {
855
- if (!$mol_compare_deep(prev, next)) {
856
- this.emit();
857
- }
858
- }
859
- }
860
- this.cursor = $mol_wire_cursor.fresh;
861
- if (next instanceof Promise)
862
- return next;
863
- if (this instanceof $mol_wire_fiber_persist) {
864
- this.complete_pubs();
865
- }
866
- else {
867
- this.cursor = $mol_wire_cursor.final;
868
- if (this.sub_empty)
869
- this.destructor();
870
- }
871
- return next;
872
- }
873
716
  sync() {
874
717
  if (!$mol_wire_fiber.warm) {
875
718
  return this.result();
@@ -906,40 +749,137 @@ var $;
906
749
  "use strict";
907
750
  var $;
908
751
  (function ($) {
909
- function $mol_wire_probe(task, next) {
910
- const warm = $mol_wire_fiber.warm;
752
+ $.$mol_compare_deep_cache = new WeakMap();
753
+ function $mol_compare_deep(left, right) {
754
+ if (Object.is(left, right))
755
+ return true;
756
+ if (left === null)
757
+ return false;
758
+ if (right === null)
759
+ return false;
760
+ if (typeof left !== 'object')
761
+ return false;
762
+ if (typeof right !== 'object')
763
+ return false;
764
+ const left_proto = Reflect.getPrototypeOf(left);
765
+ const right_proto = Reflect.getPrototypeOf(right);
766
+ if (left_proto !== right_proto)
767
+ return false;
768
+ if (left instanceof Boolean)
769
+ return Object.is(left.valueOf(), right['valueOf']());
770
+ if (left instanceof Number)
771
+ return Object.is(left.valueOf(), right['valueOf']());
772
+ if (left instanceof String)
773
+ return Object.is(left.valueOf(), right['valueOf']());
774
+ if (left instanceof Date)
775
+ return Object.is(left.valueOf(), right['valueOf']());
776
+ if (left instanceof RegExp)
777
+ return left.source === right['source'] && left.flags === right['flags'];
778
+ let left_cache = $.$mol_compare_deep_cache.get(left);
779
+ if (left_cache) {
780
+ const right_cache = left_cache.get(right);
781
+ if (typeof right_cache === 'boolean')
782
+ return right_cache;
783
+ }
784
+ else {
785
+ left_cache = new WeakMap([[right, true]]);
786
+ $.$mol_compare_deep_cache.set(left, left_cache);
787
+ }
788
+ let result;
911
789
  try {
912
- $mol_wire_fiber.warm = false;
913
- return task();
790
+ if (left_proto && !Reflect.getPrototypeOf(left_proto))
791
+ result = compare_pojo(left, right);
792
+ else if (Array.isArray(left))
793
+ result = compare_array(left, right);
794
+ else if (left instanceof Set)
795
+ result = compare_set(left, right);
796
+ else if (left instanceof Map)
797
+ result = compare_map(left, right);
798
+ else if (left instanceof Error)
799
+ result = left.stack === right.stack;
800
+ else if (ArrayBuffer.isView(left))
801
+ result = compare_buffer(left, right);
802
+ else if (Symbol.toPrimitive in left)
803
+ result = compare_primitive(left, right);
804
+ else
805
+ result = false;
914
806
  }
915
807
  finally {
916
- $mol_wire_fiber.warm = warm;
808
+ left_cache.set(right, result);
917
809
  }
810
+ return result;
918
811
  }
919
- $.$mol_wire_probe = $mol_wire_probe;
920
- })($ || ($ = {}));
921
- //mol/wire/probe/probe.ts
922
- ;
923
- "use strict";
924
- var $;
925
- (function ($) {
926
- function $mol_wire_solid() {
927
- $mol_wire_auto().reap = nothing;
812
+ $.$mol_compare_deep = $mol_compare_deep;
813
+ function compare_array(left, right) {
814
+ const len = left.length;
815
+ if (len !== right.length)
816
+ return false;
817
+ for (let i = 0; i < len; ++i) {
818
+ if (!$mol_compare_deep(left[i], right[i]))
819
+ return false;
820
+ }
821
+ return true;
822
+ }
823
+ function compare_buffer(left, right) {
824
+ const len = left.byteLength;
825
+ if (len !== right.byteLength)
826
+ return false;
827
+ for (let i = 0; i < len; ++i) {
828
+ if (left[i] !== right[i])
829
+ return false;
830
+ }
831
+ return true;
832
+ }
833
+ function compare_iterator(left, right, compare) {
834
+ while (true) {
835
+ const left_next = left.next();
836
+ const right_next = right.next();
837
+ if (left_next.done !== right_next.done)
838
+ return false;
839
+ if (left_next.done)
840
+ break;
841
+ if (!compare(left_next.value, right_next.value))
842
+ return false;
843
+ }
844
+ return true;
845
+ }
846
+ function compare_set(left, right) {
847
+ if (left.size !== right.size)
848
+ return false;
849
+ return compare_iterator(left.values(), right.values(), $mol_compare_deep);
850
+ }
851
+ function compare_map(left, right) {
852
+ if (left.size !== right.size)
853
+ return false;
854
+ return compare_iterator(left.keys(), right.keys(), Object.is)
855
+ && compare_iterator(left.values(), right.values(), $mol_compare_deep);
856
+ }
857
+ function compare_pojo(left, right) {
858
+ const left_keys = Object.getOwnPropertyNames(left);
859
+ const right_keys = Object.getOwnPropertyNames(right);
860
+ if (left_keys.length !== right_keys.length)
861
+ return false;
862
+ for (let key of left_keys) {
863
+ if (!$mol_compare_deep(left[key], Reflect.get(right, key)))
864
+ return false;
865
+ }
866
+ return true;
867
+ }
868
+ function compare_primitive(left, right) {
869
+ return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
928
870
  }
929
- $.$mol_wire_solid = $mol_wire_solid;
930
- const nothing = () => { };
931
871
  })($ || ($ = {}));
932
- //mol/wire/solid/solid.ts
872
+ //mol/compare/deep/deep.ts
933
873
  ;
934
874
  "use strict";
935
875
  var $;
936
876
  (function ($) {
937
- class $mol_wire_fiber_temp extends $mol_wire_fiber {
877
+ class $mol_wire_task extends $mol_wire_fiber {
938
878
  static getter(task) {
939
879
  return function $mol_wire_fiber_temp_get(host, args) {
940
880
  const existen = $mol_wire_auto()?.track_next();
941
881
  reuse: if (existen) {
942
- if (!(existen instanceof $mol_wire_fiber_temp))
882
+ if (!(existen instanceof $mol_wire_task))
943
883
  break reuse;
944
884
  if (existen.host !== host)
945
885
  break reuse;
@@ -949,61 +889,32 @@ var $;
949
889
  break reuse;
950
890
  return existen;
951
891
  }
952
- return new $mol_wire_fiber_temp(`${host?.[Symbol.toStringTag] ?? host}.${task.name}(#)`, task, host, ...args);
892
+ return new $mol_wire_task(`${host?.[Symbol.toStringTag] ?? host}.${task.name}(#)`, task, host, ...args);
953
893
  };
954
894
  }
955
895
  complete() {
956
896
  if (this.sub_empty)
957
897
  this.destructor();
958
898
  }
959
- }
960
- $.$mol_wire_fiber_temp = $mol_wire_fiber_temp;
961
- })($ || ($ = {}));
962
- //mol/wire/fiber/temp/temp.ts
963
- ;
964
- "use strict";
965
- var $;
966
- (function ($) {
967
- function $mol_wire_sync(obj) {
968
- return new Proxy(obj, {
969
- get(obj, field) {
970
- const val = obj[field];
971
- if (typeof val !== 'function')
972
- return val;
973
- const temp = $mol_wire_fiber_temp.getter(val);
974
- return function $mol_wire_sync(...args) {
975
- const fiber = temp(obj, args);
976
- return fiber.sync();
977
- };
899
+ put(next) {
900
+ const prev = this.cache;
901
+ if (next !== prev) {
902
+ this.cache = next;
903
+ this.emit();
978
904
  }
979
- });
980
- }
981
- $.$mol_wire_sync = $mol_wire_sync;
982
- })($ || ($ = {}));
983
- //mol/wire/sync/sync.ts
984
- ;
985
- "use strict";
986
- var $;
987
- (function ($) {
988
- function $mol_wire_async(obj) {
989
- return new Proxy(obj, {
990
- get(obj, field) {
991
- const val = obj[field];
992
- if (typeof val !== 'function')
993
- return val;
994
- let fiber;
995
- const temp = $mol_wire_fiber_temp.getter(val);
996
- return function $mol_wire_async(...args) {
997
- fiber?.destructor();
998
- fiber = temp(obj, args);
999
- return fiber.async();
1000
- };
905
+ if (next instanceof Promise) {
906
+ this.cursor = $mol_wire_cursor.fresh;
907
+ return next;
1001
908
  }
1002
- });
909
+ this.cursor = $mol_wire_cursor.final;
910
+ if (this.sub_empty)
911
+ this.destructor();
912
+ return next;
913
+ }
1003
914
  }
1004
- $.$mol_wire_async = $mol_wire_async;
915
+ $.$mol_wire_task = $mol_wire_task;
1005
916
  })($ || ($ = {}));
1006
- //mol/wire/async/async.ts
917
+ //mol/wire/task/task.ts
1007
918
  ;
1008
919
  "use strict";
1009
920
  var $;
@@ -1068,7 +979,7 @@ var $;
1068
979
  if (typeof sup[field] === 'function') {
1069
980
  Object.defineProperty(orig, 'name', { value: sup[field].name });
1070
981
  }
1071
- const temp = $mol_wire_fiber_temp.getter(orig);
982
+ const temp = $mol_wire_task.getter(orig);
1072
983
  const value = function (...args) {
1073
984
  const fiber = temp(this ?? null, args);
1074
985
  return fiber.sync();
@@ -1086,7 +997,7 @@ var $;
1086
997
  "use strict";
1087
998
  var $;
1088
999
  (function ($) {
1089
- class $mol_wire_fiber_persist extends $mol_wire_fiber {
1000
+ class $mol_wire_atom extends $mol_wire_fiber {
1090
1001
  static getter(task, keys) {
1091
1002
  const field = task.name + '()';
1092
1003
  if (keys) {
@@ -1102,7 +1013,7 @@ var $;
1102
1013
  else {
1103
1014
  dict = (host ?? task)[field] = new Map();
1104
1015
  }
1105
- fiber = new $mol_wire_fiber_persist(key, task, host, ...args);
1016
+ fiber = new $mol_wire_atom(key, task, host, ...args);
1106
1017
  dict.set(key, fiber);
1107
1018
  return fiber;
1108
1019
  };
@@ -1113,7 +1024,7 @@ var $;
1113
1024
  if (existen)
1114
1025
  return existen;
1115
1026
  const key = `${host?.[Symbol.toStringTag] ?? host}.${field}`;
1116
- const fiber = new $mol_wire_fiber_persist(key, task, host, ...args);
1027
+ const fiber = new $mol_wire_atom(key, task, host, ...args);
1117
1028
  (host ?? task)[field] = fiber;
1118
1029
  return fiber;
1119
1030
  };
@@ -1149,16 +1060,113 @@ var $;
1149
1060
  (this.host ?? this.task)[this.field()].delete(this[Symbol.toStringTag]);
1150
1061
  }
1151
1062
  }
1063
+ put(next) {
1064
+ const prev = this.cache;
1065
+ if (next !== prev) {
1066
+ if ($mol_owning_check(this, prev)) {
1067
+ prev.destructor();
1068
+ }
1069
+ this.cache = next;
1070
+ if ($mol_owning_catch(this, next)) {
1071
+ try {
1072
+ next[Symbol.toStringTag] = this[Symbol.toStringTag];
1073
+ }
1074
+ catch { }
1075
+ }
1076
+ if (this.sub_from < this.length) {
1077
+ if (!$mol_compare_deep(prev, next)) {
1078
+ this.emit();
1079
+ }
1080
+ }
1081
+ }
1082
+ this.cursor = $mol_wire_cursor.fresh;
1083
+ if (next instanceof Promise)
1084
+ return next;
1085
+ this.complete_pubs();
1086
+ return next;
1087
+ }
1152
1088
  }
1153
1089
  __decorate([
1154
1090
  $mol_wire_method
1155
- ], $mol_wire_fiber_persist.prototype, "recall", null);
1091
+ ], $mol_wire_atom.prototype, "recall", null);
1156
1092
  __decorate([
1157
1093
  $mol_wire_method
1158
- ], $mol_wire_fiber_persist.prototype, "once", null);
1159
- $.$mol_wire_fiber_persist = $mol_wire_fiber_persist;
1094
+ ], $mol_wire_atom.prototype, "once", null);
1095
+ $.$mol_wire_atom = $mol_wire_atom;
1096
+ })($ || ($ = {}));
1097
+ //mol/wire/atom/atom.ts
1098
+ ;
1099
+ "use strict";
1100
+ var $;
1101
+ (function ($) {
1102
+ function $mol_wire_probe(task, next) {
1103
+ const warm = $mol_wire_fiber.warm;
1104
+ try {
1105
+ $mol_wire_fiber.warm = false;
1106
+ return task();
1107
+ }
1108
+ finally {
1109
+ $mol_wire_fiber.warm = warm;
1110
+ }
1111
+ }
1112
+ $.$mol_wire_probe = $mol_wire_probe;
1113
+ })($ || ($ = {}));
1114
+ //mol/wire/probe/probe.ts
1115
+ ;
1116
+ "use strict";
1117
+ var $;
1118
+ (function ($) {
1119
+ function $mol_wire_solid() {
1120
+ $mol_wire_auto().reap = nothing;
1121
+ }
1122
+ $.$mol_wire_solid = $mol_wire_solid;
1123
+ const nothing = () => { };
1160
1124
  })($ || ($ = {}));
1161
- //mol/wire/fiber/persist/persist.ts
1125
+ //mol/wire/solid/solid.ts
1126
+ ;
1127
+ "use strict";
1128
+ var $;
1129
+ (function ($) {
1130
+ function $mol_wire_sync(obj) {
1131
+ return new Proxy(obj, {
1132
+ get(obj, field) {
1133
+ const val = obj[field];
1134
+ if (typeof val !== 'function')
1135
+ return val;
1136
+ const temp = $mol_wire_task.getter(val);
1137
+ return function $mol_wire_sync(...args) {
1138
+ const fiber = temp(obj, args);
1139
+ return fiber.sync();
1140
+ };
1141
+ }
1142
+ });
1143
+ }
1144
+ $.$mol_wire_sync = $mol_wire_sync;
1145
+ })($ || ($ = {}));
1146
+ //mol/wire/sync/sync.ts
1147
+ ;
1148
+ "use strict";
1149
+ var $;
1150
+ (function ($) {
1151
+ function $mol_wire_async(obj) {
1152
+ return new Proxy(obj, {
1153
+ get(obj, field) {
1154
+ const val = obj[field];
1155
+ if (typeof val !== 'function')
1156
+ return val;
1157
+ let fiber;
1158
+ const temp = $mol_wire_task.getter(val);
1159
+ return function $mol_wire_async(...args) {
1160
+ fiber?.destructor();
1161
+ fiber = temp(obj, args);
1162
+ return fiber.async();
1163
+ };
1164
+ }
1165
+ });
1166
+ }
1167
+ $.$mol_wire_async = $mol_wire_async;
1168
+ })($ || ($ = {}));
1169
+ //mol/wire/async/async.ts
1162
1170
  ;
1163
1171
  "use strict";
1164
1172
  var $;
@@ -1184,11 +1192,11 @@ var $;
1184
1192
  $.$mol_wire_mem = $mol_wire_mem;
1185
1193
  function $mol_wire_mem_func(keys) {
1186
1194
  return (func) => {
1187
- const persist = $mol_wire_fiber_persist.getter(func, keys);
1195
+ const persist = $mol_wire_atom.getter(func, keys);
1188
1196
  const wrapper = function (...args) {
1189
1197
  let atom = persist(this, args.slice(0, keys));
1190
1198
  if (args.length <= keys || args[keys] === undefined) {
1191
- if ($mol_wire_auto() instanceof $mol_wire_fiber_temp) {
1199
+ if ($mol_wire_auto() instanceof $mol_wire_task) {
1192
1200
  return atom.once();
1193
1201
  }
1194
1202
  else {
@@ -1226,7 +1234,7 @@ var $;
1226
1234
  if (!descr)
1227
1235
  descr = Reflect.getOwnPropertyDescriptor(host, field);
1228
1236
  const _get = descr?.get || $mol_const(descr?.value);
1229
- const persist = $mol_wire_fiber_persist.getter(_get, 0);
1237
+ const persist = $mol_wire_atom.getter(_get, 0);
1230
1238
  const _set = descr?.set || function (next) {
1231
1239
  persist(this, []).put(next);
1232
1240
  };
@@ -1237,7 +1245,7 @@ var $;
1237
1245
  function get() {
1238
1246
  return persist(this, []).sync();
1239
1247
  }
1240
- const temp = $mol_wire_fiber_temp.getter(_set);
1248
+ const temp = $mol_wire_task.getter(_set);
1241
1249
  function set(next) {
1242
1250
  temp(this, [next]).sync();
1243
1251
  }