teamplay 0.4.0-alpha.94 → 0.4.0-alpha.95

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,10 +1,12 @@
1
1
  import { getRaw } from '../dataTree.js'
2
2
  import { getConnection } from '../connection.js'
3
3
  import { isMissingShareDoc } from '../missingDoc.js'
4
- import { QUERIES, HASH, PARAMS, COLLECTION_NAME } from '../Query.js'
5
- import { AGGREGATIONS, IS_AGGREGATION } from '../Aggregation.js'
4
+ import { QUERIES, HASH, PARAMS, COLLECTION_NAME, querySubscriptions } from '../Query.js'
5
+ import { AGGREGATIONS, IS_AGGREGATION, aggregationSubscriptions } from '../Aggregation.js'
6
6
  import { getPrivateData, setPrivateData } from '../privateData.js'
7
7
  import { getRoot, ROOT_ID } from '../Root.js'
8
+ import { isRootContextClosed } from '../rootContext.js'
9
+ import { getScopedSignalHash, normalizeRootId } from '../rootScope.js'
8
10
 
9
11
  let imperativeQueryReadyTimeoutMs = 1000
10
12
 
@@ -47,7 +49,9 @@ export function isDocReady (segments) {
47
49
  export async function waitForImperativeQueryReady ($query) {
48
50
  const timeoutMs = imperativeQueryReadyTimeoutMs
49
51
  const startedAt = Date.now()
52
+ const ownerState = createImperativeOwnerState($query)
50
53
  while (true) {
54
+ if (isImperativeQueryCancelled($query, ownerState)) return
51
55
  if (isImperativeQueryReady($query)) {
52
56
  syncQueryDocsFromCollection($query)
53
57
  return
@@ -92,6 +96,28 @@ function isImperativeQueryReady ($query) {
92
96
  return true
93
97
  }
94
98
 
99
+ function isImperativeQueryCancelled ($query, ownerState) {
100
+ const rootId = getRoot($query)?.[ROOT_ID]
101
+ if (isRootContextClosed(rootId)) return true
102
+ if (!ownerState?.wasTracked) return false
103
+ const trackedOwnerCount = ownerState.subscriptions.getTrackedOwnerCount(ownerState.ownerKey)
104
+ return trackedOwnerCount == null || trackedOwnerCount <= 0
105
+ }
106
+
107
+ function createImperativeOwnerState ($query) {
108
+ const hash = $query[HASH]
109
+ const rootId = normalizeRootId(getRoot($query)?.[ROOT_ID])
110
+ const subscriptions = ($query[IS_AGGREGATION] || isAggregationQuery($query[PARAMS]))
111
+ ? aggregationSubscriptions
112
+ : querySubscriptions
113
+ const ownerKey = getScopedSignalHash(rootId, hash, 'queryOwner')
114
+ return {
115
+ subscriptions,
116
+ ownerKey,
117
+ wasTracked: subscriptions.getTrackedOwnerCount(ownerKey) != null
118
+ }
119
+ }
120
+
95
121
  function syncQueryDocsFromCollection ($query) {
96
122
  const params = $query[PARAMS]
97
123
  if ($query[IS_AGGREGATION] || isAggregationQuery(params) || isExtraQuery(params)) return
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teamplay",
3
- "version": "0.4.0-alpha.94",
3
+ "version": "0.4.0-alpha.95",
4
4
  "description": "Full-stack signals ORM with multiplayer",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -83,5 +83,5 @@
83
83
  ]
84
84
  },
85
85
  "license": "MIT",
86
- "gitHead": "28a9de4a846b5f36c31033c1c3486074cf9b86fc"
86
+ "gitHead": "43c734951b848a2da50848e9930e50cdf7fdd9d1"
87
87
  }