aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client/DocServer.ts8
-rw-r--r--src/new_fields/Doc.ts9
-rw-r--r--src/new_fields/RefField.ts2
3 files changed, 10 insertions, 9 deletions
diff --git a/src/client/DocServer.ts b/src/client/DocServer.ts
index 077c8e5ba..de5e052b9 100644
--- a/src/client/DocServer.ts
+++ b/src/client/DocServer.ts
@@ -26,7 +26,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 = {};
@@ -303,9 +302,6 @@ export namespace DocServer {
}
function _UpdateFieldImpl(id: string, diff: any) {
- if (id === updatingId) {
- return;
- }
Utils.Emit(_socket, MessageStore.UpdateField, { id, diff });
}
@@ -328,11 +324,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;
}