aboutsummaryrefslogtreecommitdiff
path: root/src/fields
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2020-10-05 11:59:48 -0400
committerbobzel <zzzman@gmail.com>2020-10-05 11:59:48 -0400
commit2a5cceb16d102a2139ca876983577eb8d882e9e0 (patch)
tree93abb019c104c69b69e5f664b43fdf5fa1417535 /src/fields
parentb725cbb244136ddfffad24d4ac68b9beb31845a3 (diff)
handled concurrent list additions as a special case (need to handle all concurrent edits still).
Diffstat (limited to 'src/fields')
-rw-r--r--src/fields/List.ts4
-rw-r--r--src/fields/util.ts22
2 files changed, 14 insertions, 12 deletions
diff --git a/src/fields/List.ts b/src/fields/List.ts
index c9e4bd3c1..dca8d111c 100644
--- a/src/fields/List.ts
+++ b/src/fields/List.ts
@@ -43,7 +43,7 @@ const listHandlers: any = {
}
}
const res = list.__fields.push(...items);
- this[Update]();
+ this[Update]("$addToSet");
return res;
}),
reverse() {
@@ -314,7 +314,7 @@ class ListImpl<T extends Field> extends ObjectField {
// console.log(diff);
const update = this[OnUpdate];
// update && update(diff);
- update?.();
+ update?.(diff);
}
private [Self] = this;
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);
};