aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTyler Schicke <tyler_schicke@brown.edu>2019-05-01 02:22:00 -0400
committerTyler Schicke <tyler_schicke@brown.edu>2019-05-01 02:22:00 -0400
commit5d1a60b3df65b801de504c3d7b08d6a1fc9ef03b (patch)
tree012b04720e546af3196ccdb984bef1147ba34183
parent976a4d835840e08f3dfd114757d7cddda5614b83 (diff)
Added collaboration functionality
-rw-r--r--src/client/DocServer.ts8
-rw-r--r--src/new_fields/Doc.ts17
2 files changed, 23 insertions, 2 deletions
diff --git a/src/client/DocServer.ts b/src/client/DocServer.ts
index 31a50adbd..1d73abd1f 100644
--- a/src/client/DocServer.ts
+++ b/src/client/DocServer.ts
@@ -81,6 +81,9 @@ export namespace DocServer {
}
export function UpdateField(id: string, diff: any) {
+ if (id === updatingId) {
+ return;
+ }
Utils.Emit(_socket, MessageStore.UpdateField, { id, diff });
}
@@ -91,6 +94,7 @@ export namespace DocServer {
Utils.Emit(_socket, MessageStore.CreateField, initialState);
}
+ let updatingId: string | undefined;
function respondToUpdate(diff: any) {
const id = diff.id;
if (id === undefined) {
@@ -103,7 +107,9 @@ export namespace DocServer {
}
const handler = f[HandleUpdate];
if (handler) {
- handler(diff);
+ updatingId = id;
+ handler.call(f, diff.diff);
+ updatingId = undefined;
}
};
if (field instanceof Promise) {
diff --git a/src/new_fields/Doc.ts b/src/new_fields/Doc.ts
index b2979af11..6162b3c76 100644
--- a/src/new_fields/Doc.ts
+++ b/src/new_fields/Doc.ts
@@ -8,7 +8,7 @@ import { UndoManager, undoBatch } from "../client/util/UndoManager";
import { listSpec } from "./Schema";
import { List } from "./List";
import { ObjectField, Parent, OnUpdate } from "./ObjectField";
-import { RefField, FieldId, Id } from "./RefField";
+import { RefField, FieldId, Id, HandleUpdate } from "./RefField";
import { Docs } from "../client/documents/Documents";
export function IsField(field: any): field is Field {
@@ -86,6 +86,21 @@ export class Doc extends RefField {
private [SelfProxy]: any;
public [WidthSym] = () => NumCast(this.__fields.width); // bcz: is this the right way to access width/height? it didn't work with : this.width
public [HeightSym] = () => NumCast(this.__fields.height);
+
+ public [HandleUpdate](diff: any) {
+ console.log(diff);
+ const set = diff.$set;
+ if (set) {
+ for (const key in set) {
+ if (!key.startsWith("fields.")) {
+ continue;
+ }
+ const value = SerializationHelper.Deserialize(set[key]);
+ const fKey = key.substring(7);
+ this[fKey] = value;
+ }
+ }
+ }
}
export namespace Doc {