teamplay 0.4.0-alpha.20 → 0.4.0-alpha.22
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/orm/Compat/hooksCompat.js +12 -2
- package/orm/Query.js +16 -1
- package/package.json +2 -2
|
@@ -97,7 +97,8 @@ export function useBatchDoc (collection, id, options) {
|
|
|
97
97
|
|
|
98
98
|
export function useBatchDoc$ (collection, id, _options) {
|
|
99
99
|
const $doc = getDocSignal(collection, id, 'useBatchDoc')
|
|
100
|
-
|
|
100
|
+
const options = _options ? { ..._options, ...BATCH_SUB_OPTIONS } : BATCH_SUB_OPTIONS
|
|
101
|
+
return useSub($doc, undefined, options)
|
|
101
102
|
}
|
|
102
103
|
|
|
103
104
|
export function useAsyncDoc$ (collection, id, options) {
|
|
@@ -140,7 +141,8 @@ export function useAsyncQuery (collection, query, options) {
|
|
|
140
141
|
|
|
141
142
|
export function useBatchQuery$ (collection, query, _options) {
|
|
142
143
|
const $collection = getCollectionSignal(collection, query, 'useBatchQuery')
|
|
143
|
-
|
|
144
|
+
const options = _options ? { ..._options, ...BATCH_SUB_OPTIONS } : BATCH_SUB_OPTIONS
|
|
145
|
+
return useSub($collection, normalizeQuery(query, 'useBatchQuery'), options)
|
|
144
146
|
}
|
|
145
147
|
|
|
146
148
|
export function useBatchQuery (collection, query, options) {
|
|
@@ -306,3 +308,11 @@ function normalizeQuery (query, hookName) {
|
|
|
306
308
|
}
|
|
307
309
|
return query
|
|
308
310
|
}
|
|
311
|
+
|
|
312
|
+
const BATCH_SUB_OPTIONS = Object.freeze({
|
|
313
|
+
async: false,
|
|
314
|
+
batch: true,
|
|
315
|
+
// Batch hooks are a hard suspense barrier. Deferred params can skip the barrier
|
|
316
|
+
// on route transitions and cause immediate reads from stale/empty local nodes.
|
|
317
|
+
defer: false
|
|
318
|
+
})
|
package/orm/Query.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { raw } from '@nx-js/observer-util'
|
|
2
|
-
import { get as _get, set as _set, del as _del } from './dataTree.js'
|
|
2
|
+
import { get as _get, set as _set, del as _del, getRaw } from './dataTree.js'
|
|
3
3
|
import getSignal from './getSignal.js'
|
|
4
4
|
import { getConnection, fetchOnly } from './connection.js'
|
|
5
5
|
import { emitModelChange, isModelEventsEnabled } from './Compat/modelEvents.js'
|
|
6
|
+
import { isCompatEnv } from './compatEnv.js'
|
|
6
7
|
import { docSubscriptions } from './Doc.js'
|
|
7
8
|
import FinalizationRegistry from '../utils/MockFinalizationRegistry.js'
|
|
8
9
|
import SubscriptionState from './SubscriptionState.js'
|
|
@@ -76,6 +77,7 @@ export class Query {
|
|
|
76
77
|
|
|
77
78
|
_initData () {
|
|
78
79
|
{ // reference the fetched docs
|
|
80
|
+
maybeMaterializeQueryDocsToCollection(this.collectionName, this.shareQuery.results)
|
|
79
81
|
const docs = this.shareQuery.results.map(doc => {
|
|
80
82
|
const idFields = getIdFieldsForSegments([this.collectionName, doc.id])
|
|
81
83
|
if (isPlainObject(doc.data)) injectIdFields(doc.data, idFields, doc.id)
|
|
@@ -98,6 +100,7 @@ export class Query {
|
|
|
98
100
|
}
|
|
99
101
|
|
|
100
102
|
this.shareQuery.on('insert', (shareDocs, index) => {
|
|
103
|
+
maybeMaterializeQueryDocsToCollection(this.collectionName, shareDocs)
|
|
101
104
|
const newDocs = shareDocs.map(doc => {
|
|
102
105
|
const idFields = getIdFieldsForSegments([this.collectionName, doc.id])
|
|
103
106
|
if (isPlainObject(doc.data)) injectIdFields(doc.data, idFields, doc.id)
|
|
@@ -271,6 +274,18 @@ export class QuerySubscriptions {
|
|
|
271
274
|
|
|
272
275
|
export const querySubscriptions = new QuerySubscriptions()
|
|
273
276
|
|
|
277
|
+
function maybeMaterializeQueryDocsToCollection (collectionName, shareDocs) {
|
|
278
|
+
if (!isCompatEnv()) return
|
|
279
|
+
for (const doc of shareDocs) {
|
|
280
|
+
if (!doc?.id || doc.data == null) continue
|
|
281
|
+
const existing = getRaw([collectionName, doc.id])
|
|
282
|
+
if (existing != null) continue
|
|
283
|
+
const idFields = getIdFieldsForSegments([collectionName, doc.id])
|
|
284
|
+
if (isPlainObject(doc.data)) injectIdFields(doc.data, idFields, doc.id)
|
|
285
|
+
_set([collectionName, doc.id], raw(doc.data))
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
274
289
|
export function hashQuery (collectionName, params) {
|
|
275
290
|
// TODO: probably makes sense to use fast-stable-json-stringify for this because of the params
|
|
276
291
|
return JSON.stringify({ query: [collectionName, params] })
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "teamplay",
|
|
3
|
-
"version": "0.4.0-alpha.
|
|
3
|
+
"version": "0.4.0-alpha.22",
|
|
4
4
|
"description": "Full-stack signals ORM with multiplayer",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -81,5 +81,5 @@
|
|
|
81
81
|
]
|
|
82
82
|
},
|
|
83
83
|
"license": "MIT",
|
|
84
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "c66a5b5dbfe9d2ff95f9531c31b0794d2b647ce7"
|
|
85
85
|
}
|