teamplay 0.4.0-alpha.74 → 0.4.0-alpha.76
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.
|
@@ -15,6 +15,7 @@ import { IS_QUERY, getQuerySignal, querySubscriptions } from '../Query.js'
|
|
|
15
15
|
import { IS_AGGREGATION, aggregationSubscriptions, getAggregationSignal } from '../Aggregation.js'
|
|
16
16
|
import { getIdFieldsForSegments, isIdFieldPath, normalizeIdFields, isPlainObject } from '../idFields.js'
|
|
17
17
|
import {
|
|
18
|
+
del as _del,
|
|
18
19
|
setReplace as _setReplace,
|
|
19
20
|
incrementPublic as _incrementPublic,
|
|
20
21
|
arrayPush as _arrayPush,
|
|
@@ -916,8 +917,15 @@ function isMissingPublicDocDeleteError ($signal, error) {
|
|
|
916
917
|
|
|
917
918
|
async function setDiffDeepOnSignal ($target, value) {
|
|
918
919
|
if ($target[SEGMENTS].length === 0) throw Error('Can\'t set the root signal data')
|
|
919
|
-
|
|
920
|
-
|
|
920
|
+
// Use peek() here. compat start() writes via setDiffDeep inside an observer and must not
|
|
921
|
+
// subscribe to its own target, otherwise later local edits on child signals cause start()
|
|
922
|
+
// to rerun and overwrite them from source.
|
|
923
|
+
const before = $target.peek()
|
|
924
|
+
if (isPublicCollection($target[SEGMENTS][0])) {
|
|
925
|
+
await diffDeepCompat($target, before, value)
|
|
926
|
+
return
|
|
927
|
+
}
|
|
928
|
+
diffDeepCompatSync($target, before, value)
|
|
921
929
|
}
|
|
922
930
|
|
|
923
931
|
async function diffDeepCompat ($signal, before, after) {
|
|
@@ -949,6 +957,35 @@ async function diffDeepCompat ($signal, before, after) {
|
|
|
949
957
|
await SignalCompat.prototype.set.call($signal, after)
|
|
950
958
|
}
|
|
951
959
|
|
|
960
|
+
function diffDeepCompatSync ($signal, before, after) {
|
|
961
|
+
if (before === after) return
|
|
962
|
+
|
|
963
|
+
if (Array.isArray(before) && Array.isArray(after)) {
|
|
964
|
+
if (deepEqualCompat(before, after)) return
|
|
965
|
+
const changedIndexes = getChangedArrayIndexes(before, after)
|
|
966
|
+
if (before.length === after.length && changedIndexes.length === 1) {
|
|
967
|
+
const index = changedIndexes[0]
|
|
968
|
+
diffDeepCompatSync(getChildSignal($signal, index), before[index], after[index])
|
|
969
|
+
return
|
|
970
|
+
}
|
|
971
|
+
setReplacePrivateCompatSync($signal, after)
|
|
972
|
+
return
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
if (isDiffableObject(before, after)) {
|
|
976
|
+
for (const key of Object.keys(before)) {
|
|
977
|
+
if (Object.prototype.hasOwnProperty.call(after, key)) continue
|
|
978
|
+
delPrivateCompatSync(getChildSignal($signal, key))
|
|
979
|
+
}
|
|
980
|
+
for (const key of Object.keys(after)) {
|
|
981
|
+
diffDeepCompatSync(getChildSignal($signal, key), before[key], after[key])
|
|
982
|
+
}
|
|
983
|
+
return
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
setReplacePrivateCompatSync($signal, after)
|
|
987
|
+
}
|
|
988
|
+
|
|
952
989
|
function isDiffableObject (before, after) {
|
|
953
990
|
if (!isPlainObject(before) || !isPlainObject(after)) return false
|
|
954
991
|
if (isReactLike(before) || isReactLike(after)) return false
|
|
@@ -972,6 +1009,26 @@ function getChildSignal ($parent, key) {
|
|
|
972
1009
|
return $child
|
|
973
1010
|
}
|
|
974
1011
|
|
|
1012
|
+
function setReplacePrivateCompatSync ($signal, value) {
|
|
1013
|
+
const segments = $signal[SEGMENTS]
|
|
1014
|
+
if (segments.length === 0) throw Error('Can\'t set the root signal data')
|
|
1015
|
+
const idFields = getIdFieldsForSegments(segments)
|
|
1016
|
+
if (isIdFieldPath(segments, idFields)) return
|
|
1017
|
+
if (segments.length === 2) {
|
|
1018
|
+
value = normalizeIdFields(value, idFields, segments[1])
|
|
1019
|
+
}
|
|
1020
|
+
_setReplace(segments, value)
|
|
1021
|
+
mirrorRefMutationFromTarget(segments, value)
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
function delPrivateCompatSync ($signal) {
|
|
1025
|
+
const segments = $signal[SEGMENTS]
|
|
1026
|
+
if (segments.length === 0) throw Error('Can\'t delete the root signal data')
|
|
1027
|
+
const idFields = getIdFieldsForSegments(segments)
|
|
1028
|
+
if (isIdFieldPath(segments, idFields)) return
|
|
1029
|
+
_del(segments)
|
|
1030
|
+
}
|
|
1031
|
+
|
|
975
1032
|
function deepEqualCompat (left, right) {
|
|
976
1033
|
if (left === right) return true
|
|
977
1034
|
if (left == null || right == null) return false
|
|
@@ -38,7 +38,12 @@ export function compatStartOnRoot ($root, targetPath, ...depsAndGetter) {
|
|
|
38
38
|
if (isThenable(err)) return
|
|
39
39
|
throw err
|
|
40
40
|
}
|
|
41
|
-
const
|
|
41
|
+
const detachedValue = detachStartValue(nextValue)
|
|
42
|
+
// Keep the detached snapshot to avoid aliasing source and target.
|
|
43
|
+
// Old racer start() writes through diffDeep by default. In compat mode we must preserve
|
|
44
|
+
// that behavior, but also avoid reading the target reactively inside start(), otherwise
|
|
45
|
+
// start() subscribes to its own output and local child edits get immediately overwritten.
|
|
46
|
+
const maybePromise = $target.setDiffDeep(detachedValue)
|
|
42
47
|
if (maybePromise?.catch) maybePromise.catch(ignorePromiseRejection)
|
|
43
48
|
}, { scheduler: scheduleReaction })
|
|
44
49
|
store.set(targetKey, { stop: () => unobserve(reaction) })
|
package/orm/dataTree.js
CHANGED
|
@@ -517,6 +517,14 @@ export async function incrementPublic (segments, byNumber) {
|
|
|
517
517
|
hydrateCompatDocData: true
|
|
518
518
|
})
|
|
519
519
|
if (!docState.exists) throw Error(ERRORS.nonExistingDoc(segments))
|
|
520
|
+
const current = getRaw(segments)
|
|
521
|
+
if (current == null) {
|
|
522
|
+
// Align with Racer's RemoteDoc.increment(): if the document exists but the
|
|
523
|
+
// target path is missing/null, initialize the path with the increment value
|
|
524
|
+
// instead of emitting a numeric-add op against a non-existing path.
|
|
525
|
+
await setPublicDoc(segments, byNumber)
|
|
526
|
+
return
|
|
527
|
+
}
|
|
520
528
|
const relativePath = segments.slice(2)
|
|
521
529
|
const op = [{ p: relativePath, na: byNumber }]
|
|
522
530
|
return new Promise((resolve, reject) => {
|
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.76",
|
|
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": "954f4352b0641286b46c015a152175929eb979bc"
|
|
87
87
|
}
|