teamplay 0.4.0-alpha.63 → 0.4.0-alpha.65
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.
|
@@ -9,6 +9,7 @@ import { hashQuery, QUERIES } from '../Query.js'
|
|
|
9
9
|
import { AGGREGATIONS } from '../Aggregation.js'
|
|
10
10
|
|
|
11
11
|
const $root = getRootSignal({ rootId: GLOBAL_ROOT_ID, rootFunction: universal$ })
|
|
12
|
+
const emittedCompatWarnings = new Set()
|
|
12
13
|
|
|
13
14
|
// Hook-compatible wrapper around $() for compatibility mode.
|
|
14
15
|
export function useValue$ (defaultValue) {
|
|
@@ -288,7 +289,7 @@ function getDocSignal (collection, id, hookName) {
|
|
|
288
289
|
throw Error(`[${hookName}] collection must be a string. Got: ${collection}`)
|
|
289
290
|
}
|
|
290
291
|
if (id == null) {
|
|
291
|
-
|
|
292
|
+
warnCompatOnce(`doc:${hookName}:${collection}:${id}`, `
|
|
292
293
|
[${hookName}] You are trying to subscribe to an undefined document id:
|
|
293
294
|
${collection}.${id}
|
|
294
295
|
Falling back to '__NULL__' document to prevent critical crash.
|
|
@@ -304,7 +305,7 @@ function getCollectionSignal (collection, query, hookName) {
|
|
|
304
305
|
throw Error(`[${hookName}] collection must be a string. Got: ${collection}`)
|
|
305
306
|
}
|
|
306
307
|
if (query == null) {
|
|
307
|
-
|
|
308
|
+
warnCompatOnce(`query:${hookName}:${collection}`, `
|
|
308
309
|
[${hookName}] Query is undefined. Got:
|
|
309
310
|
${collection}, ${query}
|
|
310
311
|
Falling back to {_id: '__NON_EXISTENT__'} query to prevent critical crash.
|
|
@@ -314,6 +315,16 @@ function getCollectionSignal (collection, query, hookName) {
|
|
|
314
315
|
return $root[collection]
|
|
315
316
|
}
|
|
316
317
|
|
|
318
|
+
function warnCompatOnce (key, message) {
|
|
319
|
+
if (emittedCompatWarnings.has(key)) return
|
|
320
|
+
emittedCompatWarnings.add(key)
|
|
321
|
+
console.warn(message)
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
export function __resetCompatWarningsForTests () {
|
|
325
|
+
emittedCompatWarnings.clear()
|
|
326
|
+
}
|
|
327
|
+
|
|
317
328
|
function normalizeQuery (query, hookName) {
|
|
318
329
|
if (query == null) return { _id: '__NON_EXISTENT__' }
|
|
319
330
|
if (typeof query !== 'object') {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { observe, unobserve } from '@nx-js/observer-util'
|
|
1
|
+
import { observe, raw, unobserve } from '@nx-js/observer-util'
|
|
2
2
|
import { getRoot } from '../Root.js'
|
|
3
3
|
import { scheduleReaction } from '../batchScheduler.js'
|
|
4
4
|
|
|
@@ -38,7 +38,7 @@ export function compatStartOnRoot ($root, targetPath, ...depsAndGetter) {
|
|
|
38
38
|
if (isThenable(err)) return
|
|
39
39
|
throw err
|
|
40
40
|
}
|
|
41
|
-
const maybePromise = $target.set(nextValue)
|
|
41
|
+
const maybePromise = $target.set(detachStartValue(nextValue))
|
|
42
42
|
if (maybePromise?.catch) maybePromise.catch(ignorePromiseRejection)
|
|
43
43
|
}, { scheduler: scheduleReaction })
|
|
44
44
|
store.set(targetKey, { stop: () => unobserve(reaction) })
|
|
@@ -105,3 +105,36 @@ function ignorePromiseRejection () {}
|
|
|
105
105
|
function isThenable (value) {
|
|
106
106
|
return !!value && typeof value.then === 'function'
|
|
107
107
|
}
|
|
108
|
+
|
|
109
|
+
function detachStartValue (value) {
|
|
110
|
+
const rawValue = raw(value)
|
|
111
|
+
if (!rawValue || typeof rawValue !== 'object') return rawValue
|
|
112
|
+
if (typeof globalThis.structuredClone === 'function') {
|
|
113
|
+
try {
|
|
114
|
+
return globalThis.structuredClone(rawValue)
|
|
115
|
+
} catch {}
|
|
116
|
+
}
|
|
117
|
+
return racerDeepCopy(rawValue)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function racerDeepCopy (value) {
|
|
121
|
+
if (value instanceof Date) return new Date(value)
|
|
122
|
+
if (typeof value === 'object') {
|
|
123
|
+
if (value === null) return null
|
|
124
|
+
if (Array.isArray(value)) {
|
|
125
|
+
const array = []
|
|
126
|
+
for (let i = value.length; i--;) {
|
|
127
|
+
array[i] = racerDeepCopy(value[i])
|
|
128
|
+
}
|
|
129
|
+
return array
|
|
130
|
+
}
|
|
131
|
+
const object = new value.constructor()
|
|
132
|
+
for (const key in value) {
|
|
133
|
+
if (Object.prototype.hasOwnProperty.call(value, key)) {
|
|
134
|
+
object[key] = racerDeepCopy(value[key])
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return object
|
|
138
|
+
}
|
|
139
|
+
return value
|
|
140
|
+
}
|
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.65",
|
|
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": "
|
|
86
|
+
"gitHead": "0c78a4d871ee08ef4f6e843ebdb41fd4d62946b4"
|
|
87
87
|
}
|