teamplay 0.4.0-alpha.64 → 0.4.0-alpha.66
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.
|
@@ -552,6 +552,27 @@ class SignalCompat extends Signal {
|
|
|
552
552
|
return onCustomEvent(eventName, pattern)
|
|
553
553
|
}
|
|
554
554
|
|
|
555
|
+
once (eventName, pattern, handler) {
|
|
556
|
+
if (arguments.length < 2) throw Error('Signal.once() expects at least two arguments')
|
|
557
|
+
const isModelEvent = eventName === 'change' || eventName === 'all'
|
|
558
|
+
if (isModelEvent && typeof pattern !== 'function') {
|
|
559
|
+
if (typeof handler !== 'function') throw Error('Signal.once() expects a handler function')
|
|
560
|
+
const onceHandler = (...args) => {
|
|
561
|
+
this.removeListener(eventName, onceHandler)
|
|
562
|
+
handler(...args)
|
|
563
|
+
}
|
|
564
|
+
this.on(eventName, pattern, onceHandler)
|
|
565
|
+
return onceHandler
|
|
566
|
+
}
|
|
567
|
+
if (typeof pattern !== 'function') throw Error('Signal.once() expects a handler function')
|
|
568
|
+
const onceHandler = (...args) => {
|
|
569
|
+
this.removeListener(eventName, onceHandler)
|
|
570
|
+
pattern(...args)
|
|
571
|
+
}
|
|
572
|
+
this.on(eventName, onceHandler)
|
|
573
|
+
return onceHandler
|
|
574
|
+
}
|
|
575
|
+
|
|
555
576
|
removeListener (eventName, handler) {
|
|
556
577
|
if (arguments.length !== 2) throw Error('Signal.removeListener() expects two arguments')
|
|
557
578
|
if (eventName === 'change' || eventName === 'all') {
|
|
@@ -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.66",
|
|
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": "ad81d82d0f15fd2b16a5d84c68472cd033419136"
|
|
87
87
|
}
|