diff options
-rw-r--r-- | src/client/DocServer.ts | 8 | ||||
-rw-r--r-- | src/new_fields/Doc.ts | 9 | ||||
-rw-r--r-- | src/new_fields/RefField.ts | 2 |
3 files changed, 10 insertions, 9 deletions
diff --git a/src/client/DocServer.ts b/src/client/DocServer.ts index df9828029..cb460799f 100644 --- a/src/client/DocServer.ts +++ b/src/client/DocServer.ts @@ -25,7 +25,6 @@ export namespace DocServer { // this client's distinct GUID created at initialization let GUID: string; // indicates whether or not a document is currently being udpated, and, if so, its id - let updatingId: string | undefined; export function init(protocol: string, hostname: string, port: number, identifier: string) { _cache = {}; @@ -302,9 +301,6 @@ export namespace DocServer { } function _UpdateFieldImpl(id: string, diff: any) { - if (id === updatingId) { - return; - } Utils.Emit(_socket, MessageStore.UpdateField, { id, diff }); } @@ -327,11 +323,7 @@ export namespace DocServer { // extract this Doc's update handler const handler = f[HandleUpdate]; if (handler) { - // set the 'I'm currently updating this Doc' flag - updatingId = id; handler.call(f, diff.diff); - // reset to indicate no ongoing updates - updatingId = undefined; } }; // check the cache for the field diff --git a/src/new_fields/Doc.ts b/src/new_fields/Doc.ts index 64b4acb7b..5e98ec48c 100644 --- a/src/new_fields/Doc.ts +++ b/src/new_fields/Doc.ts @@ -75,6 +75,8 @@ function fetchProto(doc: Doc) { } } +let updatingFromServer = false; + @scriptingGlobal @Deserializable("doc", fetchProto).withFields(["id"]) export class Doc extends RefField { @@ -129,6 +131,9 @@ export class Doc extends RefField { private ___fields: any = {}; private [Update] = (diff: any) => { + if (updatingFromServer) { + return; + } DocServer.UpdateField(this[Id], diff); } @@ -150,7 +155,9 @@ export class Doc extends RefField { } const value = await SerializationHelper.Deserialize(set[key]); const fKey = key.substring(7); + updatingFromServer = true; this[fKey] = value; + updatingFromServer = false; } } const unset = diff.$unset; @@ -160,7 +167,9 @@ export class Doc extends RefField { continue; } const fKey = key.substring(7); + updatingFromServer = true; delete this[fKey]; + updatingFromServer = false; } } } diff --git a/src/new_fields/RefField.ts b/src/new_fields/RefField.ts index 5414df2b9..f7bea8c94 100644 --- a/src/new_fields/RefField.ts +++ b/src/new_fields/RefField.ts @@ -14,7 +14,7 @@ export abstract class RefField { this[Id] = this.__id; } - protected [HandleUpdate]?(diff: any): void; + protected [HandleUpdate]?(diff: any): void | Promise<void>; abstract [ToScriptString](): string; } |