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