jazz-tools 0.8.51 → 0.9.0

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.
@@ -1,8 +1,8 @@
1
1
 
2
- > jazz-tools@0.8.51 build /home/runner/work/jazz/jazz/packages/jazz-tools
2
+ > jazz-tools@0.9.0 build /home/runner/work/jazz/jazz/packages/jazz-tools
3
3
  > tsup
4
4
 
5
- CLI Building entry: {"index.web":"src/index.web.ts","index.native":"src/index.native.ts"}
5
+ CLI Building entry: {"index.web":"src/index.web.ts","index.native":"src/index.native.ts","testing":"src/testing.ts"}
6
6
  CLI Using tsconfig: tsconfig.json
7
7
  CLI tsup v8.3.5
8
8
  CLI Using tsup config: /home/runner/work/jazz/jazz/packages/jazz-tools/tsup.config.ts
@@ -10,9 +10,11 @@
10
10
  CLI Cleaning output folder
11
11
  ESM Build start
12
12
  ESM dist/index.web.js 1.08 KB
13
+ ESM dist/testing.js 2.10 KB
13
14
  ESM dist/index.native.js 1.07 KB
14
- ESM dist/chunk-MUJIKQFH.js 82.20 KB
15
+ ESM dist/chunk-EK2I4C5W.js 82.83 KB
15
16
  ESM dist/index.web.js.map 270.00 B
17
+ ESM dist/testing.js.map 4.48 KB
18
+ ESM dist/chunk-EK2I4C5W.js.map 190.92 KB
16
19
  ESM dist/index.native.js.map 280.00 B
17
- ESM dist/chunk-MUJIKQFH.js.map 189.68 KB
18
- ESM ⚡️ Build success in 71ms
20
+ ESM ⚡️ Build success in 92ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # jazz-tools
2
2
 
3
+ ## 0.9.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 8eda792: Optimize the subscribe to resolve the CoValues stored in memory synchronously
8
+ - Updated dependencies [8eda792]
9
+ - Updated dependencies [1ef3226]
10
+ - cojson@0.9.0
11
+
3
12
  ## 0.8.51
4
13
 
5
14
  ### Patch Changes
@@ -63,6 +63,16 @@ var Ref = class _Ref {
63
63
  return new _Ref(this.id, this.controlledAccount, this.schema).value;
64
64
  }
65
65
  }
66
+ syncLoad() {
67
+ const node = "node" in this.controlledAccount ? this.controlledAccount.node : this.controlledAccount._raw.core.node;
68
+ const entry = node.coValuesStore.get(
69
+ this.id
70
+ );
71
+ if (entry.state.type === "available") {
72
+ return new _Ref(this.id, this.controlledAccount, this.schema).value;
73
+ }
74
+ return void 0;
75
+ }
66
76
  async load() {
67
77
  const result = await this.loadHelper();
68
78
  if (result === "unavailable") {
@@ -240,6 +250,16 @@ var SubscriptionScope = class {
240
250
  this.scheduledUpdate = false;
241
251
  this.cachedValues = {};
242
252
  this.parents = {};
253
+ this.unsubscribeAll = () => {
254
+ for (const entry of this.entries.values()) {
255
+ if (entry.state === "loaded") {
256
+ entry.rawUnsub();
257
+ } else {
258
+ entry.immediatelyUnsub = true;
259
+ }
260
+ }
261
+ this.entries.clear();
262
+ };
243
263
  this.rootEntry = {
244
264
  state: "loaded",
245
265
  value: root._raw,
@@ -253,7 +273,7 @@ var SubscriptionScope = class {
253
273
  this.scheduleUpdate = () => {
254
274
  const value = rootSchema.fromRaw(this.rootEntry.value);
255
275
  subscriptionsScopes.set(value, this);
256
- onUpdate(value);
276
+ onUpdate(value, this);
257
277
  };
258
278
  this.rootEntry.rawUnsub = root._raw.core.subscribe(
259
279
  (rawUpdate) => {
@@ -307,16 +327,6 @@ var SubscriptionScope = class {
307
327
  this.invalidate(parent, id, seen);
308
328
  }
309
329
  }
310
- unsubscribeAll() {
311
- for (const entry of this.entries.values()) {
312
- if (entry.state === "loaded") {
313
- entry.rawUnsub();
314
- } else {
315
- entry.immediatelyUnsub = true;
316
- }
317
- }
318
- this.entries.clear();
319
- }
320
330
  };
321
331
 
322
332
  // src/coValues/deepLoading.ts
@@ -677,18 +687,17 @@ var CoValueBase = class {
677
687
  };
678
688
  function loadCoValue(cls, id, as, depth) {
679
689
  return new Promise((resolve) => {
680
- const unsubscribe = subscribeToCoValue(
690
+ subscribeToCoValue(
681
691
  cls,
682
692
  id,
683
693
  as,
684
694
  depth,
685
- (value) => {
695
+ (value, unsubscribe) => {
686
696
  resolve(value);
687
697
  unsubscribe();
688
698
  },
689
699
  () => {
690
700
  resolve(void 0);
691
- unsubscribe();
692
701
  }
693
702
  );
694
703
  });
@@ -701,11 +710,11 @@ function ensureCoValueLoaded(existing, depth) {
701
710
  depth
702
711
  );
703
712
  }
704
- function subscribeToCoValue(cls, id, as, depth, listener, onUnavailable) {
713
+ function subscribeToCoValue(cls, id, as, depth, listener, onUnavailable, syncResolution) {
705
714
  const ref2 = new Ref(id, as, { ref: cls, optional: false });
706
715
  let unsubscribed = false;
707
716
  let unsubscribe;
708
- ref2.load().then((value) => {
717
+ function subscribe(value) {
709
718
  if (!value) {
710
719
  onUnavailable && onUnavailable();
711
720
  return;
@@ -714,22 +723,31 @@ function subscribeToCoValue(cls, id, as, depth, listener, onUnavailable) {
714
723
  const subscription = new SubscriptionScope(
715
724
  value,
716
725
  cls,
717
- (update) => {
726
+ (update, subscription2) => {
718
727
  if (fulfillsDepth(depth, update)) {
719
- listener(update);
728
+ listener(
729
+ update,
730
+ subscription2.unsubscribeAll
731
+ );
720
732
  }
721
733
  }
722
734
  );
723
- unsubscribe = () => subscription.unsubscribeAll();
724
- }).catch((e) => {
725
- console.error("Failed to load / subscribe to CoValue", e);
726
- });
735
+ unsubscribe = subscription.unsubscribeAll;
736
+ }
737
+ const sync = syncResolution ? ref2.syncLoad() : void 0;
738
+ if (sync) {
739
+ subscribe(sync);
740
+ } else {
741
+ ref2.load().then((value) => subscribe(value)).catch((e) => {
742
+ console.error("Failed to load / subscribe to CoValue", e);
743
+ });
744
+ }
727
745
  return function unsubscribeAtAnyPoint() {
728
746
  unsubscribed = true;
729
747
  unsubscribe && unsubscribe();
730
748
  };
731
749
  }
732
- function createCoValueObservable() {
750
+ function createCoValueObservable(options) {
733
751
  let currentValue = void 0;
734
752
  let subscriberCount = 0;
735
753
  function subscribe(cls, id, as, depth, listener, onUnavailable) {
@@ -743,7 +761,8 @@ function createCoValueObservable() {
743
761
  currentValue = value;
744
762
  listener();
745
763
  },
746
- onUnavailable
764
+ onUnavailable,
765
+ options?.syncResolution
747
766
  );
748
767
  return () => {
749
768
  unsubscribe();
@@ -2264,7 +2283,7 @@ var FileStream = class extends CoValueBase {
2264
2283
  let stream = await this.load(id, as, []);
2265
2284
  if (!options?.allowUnfinished && !stream?.isBinaryStreamEnded()) {
2266
2285
  stream = await new Promise((resolve) => {
2267
- const unsubscribe = subscribeToCoValue(this, id, as, [], (value) => {
2286
+ subscribeToCoValue(this, id, as, [], (value, unsubscribe) => {
2268
2287
  if (value.isBinaryStreamEnded()) {
2269
2288
  unsubscribe();
2270
2289
  resolve(value);
@@ -2503,9 +2522,11 @@ var _CoList = class _CoList extends Array {
2503
2522
  return instance;
2504
2523
  }
2505
2524
  push(...items) {
2506
- for (const item of toRawItems(items, this._schema[ItemsSym])) {
2507
- this._raw.append(item);
2508
- }
2525
+ this._raw.appendItems(
2526
+ toRawItems(items, this._schema[ItemsSym]),
2527
+ void 0,
2528
+ "private"
2529
+ );
2509
2530
  return this._raw.entries().length;
2510
2531
  }
2511
2532
  unshift(...items) {
@@ -2857,4 +2878,4 @@ export {
2857
2878
  SchemaUnion
2858
2879
  };
2859
2880
  /* istanbul ignore file -- @preserve */
2860
- //# sourceMappingURL=chunk-MUJIKQFH.js.map
2881
+ //# sourceMappingURL=chunk-EK2I4C5W.js.map