diff options
author | bobzel <zzzman@gmail.com> | 2020-10-05 11:59:48 -0400 |
---|---|---|
committer | bobzel <zzzman@gmail.com> | 2020-10-05 11:59:48 -0400 |
commit | 2a5cceb16d102a2139ca876983577eb8d882e9e0 (patch) | |
tree | 93abb019c104c69b69e5f664b43fdf5fa1417535 /src/fields/util.ts | |
parent | b725cbb244136ddfffad24d4ac68b9beb31845a3 (diff) |
handled concurrent list additions as a special case (need to handle all concurrent edits still).
Diffstat (limited to 'src/fields/util.ts')
-rw-r--r-- | src/fields/util.ts | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/fields/util.ts b/src/fields/util.ts index 4da9fce74..90446f531 100644 --- a/src/fields/util.ts +++ b/src/fields/util.ts @@ -371,17 +371,19 @@ export function deleteProperty(target: any, prop: string | number | symbol) { export function updateFunction(target: any, prop: any, value: any, receiver: any) { let current = ObjectField.MakeCopy(value); return (diff?: any) => { - if (true || !diff) { + if (diff === "$addToSet") { + diff = { '$addToSet': { ["fields." + prop]: SerializationHelper.Serialize(value) } }; + } else { diff = { '$set': { ["fields." + prop]: SerializationHelper.Serialize(value) } }; - const oldValue = current; - const newValue = ObjectField.MakeCopy(value); - current = newValue; - if (!(value instanceof CursorField) && !(value?.some?.((v: any) => v instanceof CursorField))) { - UndoManager.AddEvent({ - redo() { receiver[prop] = newValue; }, - undo() { receiver[prop] = oldValue; } - }); - } + } + const oldValue = current; + const newValue = ObjectField.MakeCopy(value); + current = newValue; + if (!(value instanceof CursorField) && !(value?.some?.((v: any) => v instanceof CursorField))) { + UndoManager.AddEvent({ + redo() { receiver[prop] = newValue; }, + undo() { receiver[prop] = oldValue; } + }); } target[Update](diff); }; |