aboutsummaryrefslogtreecommitdiff
path: root/src/new_fields/util.ts
diff options
context:
space:
mode:
authorTyler Schicke <tyler_schicke@brown.edu>2019-05-01 02:03:40 -0400
committerTyler Schicke <tyler_schicke@brown.edu>2019-05-01 02:03:40 -0400
commitca4a0a6454e69f0eeabdfb6ec78f8ecd60e18b76 (patch)
treeec23b46418f56410463201e1fc9288ba8e3bdf26 /src/new_fields/util.ts
parent770f55f12398b5791cf3f861f3ea60fac8da626d (diff)
Undo with lists is working better
Diffstat (limited to 'src/new_fields/util.ts')
-rw-r--r--src/new_fields/util.ts16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/new_fields/util.ts b/src/new_fields/util.ts
index 128817ab8..bbd8157f6 100644
--- a/src/new_fields/util.ts
+++ b/src/new_fields/util.ts
@@ -31,7 +31,7 @@ export const setter = action(function (target: any, prop: string | symbol | numb
throw new Error("Can't put the same object in multiple documents at the same time");
}
value[Parent] = target;
- value[OnUpdate] = updateFunction(target, prop, value);
+ value[OnUpdate] = updateFunction(target, prop, value, receiver);
}
if (curValue instanceof ObjectField) {
delete curValue[Parent];
@@ -86,9 +86,19 @@ export function deleteProperty(target: any, prop: string | number | symbol) {
throw new Error("Currently properties can't be deleted from documents, assign to undefined instead");
}
-export function updateFunction(target: any, prop: any, value: any) {
+export function updateFunction(target: any, prop: any, value: any, receiver: any) {
+ let current = ObjectField.MakeCopy(value);
return (diff?: any) => {
- if (!diff) diff = { '$set': { ["fields." + prop]: SerializationHelper.Serialize(value) } };
+ if (true || !diff) {
+ diff = { '$set': { ["fields." + prop]: SerializationHelper.Serialize(value) } };
+ const oldValue = current;
+ const newValue = ObjectField.MakeCopy(value);
+ current = newValue;
+ UndoManager.AddEvent({
+ redo() { receiver[prop] = newValue; },
+ undo() { receiver[prop] = oldValue; }
+ });
+ }
target[Update](diff);
};
} \ No newline at end of file