spacetimedb 2.2.0 → 2.3.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.
package/LICENSE.txt CHANGED
@@ -5,7 +5,7 @@ Business Source License 1.1
5
5
  Parameters
6
6
 
7
7
  Licensor: Clockwork Laboratories, Inc.
8
- Licensed Work: SpacetimeDB 2.2.0
8
+ Licensed Work: SpacetimeDB 2.3.0
9
9
  The Licensed Work is
10
10
  (c) 2023 Clockwork Laboratories, Inc.
11
11
 
@@ -21,7 +21,7 @@ Additional Use Grant: You may make use of the Licensed Work provided your
21
21
  Licensed Work by creating tables whose schemas are
22
22
  controlled by such third parties.
23
23
 
24
- Change Date: 2031-04-29
24
+ Change Date: 2031-05-26
25
25
 
26
26
  Change License: GNU Affero General Public License v3.0 with a linking
27
27
  exception
@@ -1739,7 +1739,42 @@ function useReducer(reducerDef) {
1739
1739
  return fn(...params);
1740
1740
  };
1741
1741
  }
1742
+ function useProcedure(procedureDef) {
1743
+ const conn = useSpacetimeDB();
1744
+ const procedureName = procedureDef.accessorName;
1745
+ const queueRef = shallowRef([]);
1746
+ const stopWatch = watch(
1747
+ () => conn.isActive,
1748
+ () => {
1749
+ const connection = conn.getConnection();
1750
+ if (!connection) return;
1751
+ const fn = connection.procedures[procedureName];
1752
+ if (queueRef.value.length) {
1753
+ const pending = queueRef.value.splice(0);
1754
+ for (const item of pending) {
1755
+ fn(...item.params).then(item.resolve, item.reject);
1756
+ }
1757
+ }
1758
+ },
1759
+ { immediate: true }
1760
+ );
1761
+ onUnmounted(() => {
1762
+ stopWatch();
1763
+ });
1764
+ return (...params) => {
1765
+ const connection = conn.getConnection();
1766
+ if (!connection) {
1767
+ return new Promise(
1768
+ (resolve, reject) => {
1769
+ queueRef.value.push({ params, resolve, reject });
1770
+ }
1771
+ );
1772
+ }
1773
+ const fn = connection.procedures[procedureName];
1774
+ return fn(...params);
1775
+ };
1776
+ }
1742
1777
 
1743
- export { SpacetimeDBProvider, useReducer, useSpacetimeDB, useSpacetimeDBProvider, useTable };
1778
+ export { SpacetimeDBProvider, useProcedure, useReducer, useSpacetimeDB, useSpacetimeDBProvider, useTable };
1744
1779
  //# sourceMappingURL=index.mjs.map
1745
1780
  //# sourceMappingURL=index.mjs.map