teamplay 0.4.0-alpha.61 → 0.4.0-alpha.63
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/eventsCompat.js +2 -1
- package/orm/dataTree.js +9 -5
- package/package.json +2 -2
- package/react/helpers.js +4 -2
|
@@ -12,7 +12,8 @@ const listeners = new Map()
|
|
|
12
12
|
export function emit (eventName, ...args) {
|
|
13
13
|
const subs = listeners.get(eventName)
|
|
14
14
|
if (!subs) return
|
|
15
|
-
|
|
15
|
+
const snapshot = Array.from(subs)
|
|
16
|
+
for (const handler of snapshot) {
|
|
16
17
|
handler(...args)
|
|
17
18
|
}
|
|
18
19
|
}
|
package/orm/dataTree.js
CHANGED
|
@@ -49,13 +49,15 @@ export function set (segments, value, tree = dataTree) {
|
|
|
49
49
|
let dataNodeRaw = raw(writableTree)
|
|
50
50
|
for (let i = 0; i < segments.length - 1; i++) {
|
|
51
51
|
const segment = segments[i]
|
|
52
|
-
|
|
52
|
+
const nextSegment = segments[i + 1]
|
|
53
|
+
const currentValue = dataNodeRaw?.[segment]
|
|
54
|
+
if (currentValue == null || typeof currentValue !== 'object') {
|
|
53
55
|
// if next segment is a number, it means that we are in the array
|
|
54
|
-
if (typeof
|
|
56
|
+
if (typeof nextSegment === 'number') dataNode[segment] = []
|
|
55
57
|
else dataNode[segment] = {}
|
|
56
58
|
}
|
|
57
59
|
dataNode = dataNode[segment]
|
|
58
|
-
dataNodeRaw =
|
|
60
|
+
dataNodeRaw = raw(dataNode)
|
|
59
61
|
}
|
|
60
62
|
const key = segments[segments.length - 1]
|
|
61
63
|
// handle adding out of bounds empty element to the array
|
|
@@ -103,9 +105,11 @@ export function setReplace (segments, value, tree = dataTree) {
|
|
|
103
105
|
let dataNode = writableTree
|
|
104
106
|
for (let i = 0; i < segments.length - 1; i++) {
|
|
105
107
|
const segment = segments[i]
|
|
106
|
-
|
|
108
|
+
const nextSegment = segments[i + 1]
|
|
109
|
+
const currentValue = dataNode[segment]
|
|
110
|
+
if (currentValue == null || typeof currentValue !== 'object') {
|
|
107
111
|
// if next segment is a number, it means that we are in the array
|
|
108
|
-
if (typeof
|
|
112
|
+
if (typeof nextSegment === 'number') dataNode[segment] = []
|
|
109
113
|
else dataNode[segment] = {}
|
|
110
114
|
}
|
|
111
115
|
dataNode = dataNode[segment]
|
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.63",
|
|
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": "3efa8ff337fbecf46a17c434e18b5d6148887033"
|
|
87
87
|
}
|
package/react/helpers.js
CHANGED
|
@@ -71,14 +71,16 @@ export function useUnmount (fn) {
|
|
|
71
71
|
|
|
72
72
|
export function useDidUpdate (fn, deps) {
|
|
73
73
|
const isFirst = useRef(true)
|
|
74
|
+
const fnRef = useRef(fn)
|
|
75
|
+
if (fnRef.current !== fn) fnRef.current = fn
|
|
74
76
|
const stableDeps = useStableDeps(deps)
|
|
75
77
|
useEffect(() => {
|
|
76
78
|
if (isFirst.current) {
|
|
77
79
|
isFirst.current = false
|
|
78
80
|
return
|
|
79
81
|
}
|
|
80
|
-
return
|
|
81
|
-
},
|
|
82
|
+
return fnRef.current()
|
|
83
|
+
}, stableDeps)
|
|
82
84
|
}
|
|
83
85
|
|
|
84
86
|
export function useOnce (condition, fn) {
|