diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/client/DocServer.ts | 8 | ||||
-rw-r--r-- | src/new_fields/Doc.ts | 17 |
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 { |