diff options
author | Sam Wilkins <samwilkins333@gmail.com> | 2019-07-25 13:01:30 -0400 |
---|---|---|
committer | Sam Wilkins <samwilkins333@gmail.com> | 2019-07-25 13:01:30 -0400 |
commit | 93515e3f152ad91c009a07bc316af9bb7676dd7d (patch) | |
tree | 66e94f18226ae2adeda07ff3347c59429de6400e | |
parent | 6c111fdc538775f9f7b04f91d0b5701fd2a1aaca (diff) | |
parent | 18a0850353b0fc55cbf7ae1d4e2763919fc78bca (diff) |
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web
-rw-r--r-- | src/client/DocServer.ts | 8 | ||||
-rw-r--r-- | src/client/util/SerializationHelper.ts | 6 | ||||
-rw-r--r-- | src/new_fields/Doc.ts | 11 | ||||
-rw-r--r-- | src/new_fields/RefField.ts | 2 |
4 files changed, 14 insertions, 13 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/client/util/SerializationHelper.ts b/src/client/util/SerializationHelper.ts index 94b640afa..034be8f67 100644 --- a/src/client/util/SerializationHelper.ts +++ b/src/client/util/SerializationHelper.ts @@ -91,15 +91,15 @@ export function Deserializable(constructor: { new(...args: any[]): any } | strin if (typeof constructor === "string") { return Object.assign((ctor: { new(...args: any[]): any }) => { addToMap(constructor, ctor); - }, { withFields: Deserializable.withFields }); + }, { withFields: (fields: string[]) => Deserializable.withFields(fields, name, afterDeserialize) }); } addToMap(constructor.name, constructor); } export namespace Deserializable { - export function withFields(fields: string[]) { + export function withFields(fields: string[], name?: string, afterDeserialize?: (obj: any) => void | Promise<any>) { return function (constructor: { new(...fields: any[]): any }) { - Deserializable(constructor); + Deserializable(name || constructor.name, afterDeserialize)(constructor); let schema = getDefaultModelSchema(constructor); if (schema) { schema.factory = context => { diff --git a/src/new_fields/Doc.ts b/src/new_fields/Doc.ts index 64b4acb7b..0a5bdc4b7 100644 --- a/src/new_fields/Doc.ts +++ b/src/new_fields/Doc.ts @@ -75,8 +75,10 @@ function fetchProto(doc: Doc) { } } +let updatingFromServer = false; + @scriptingGlobal -@Deserializable("doc", fetchProto).withFields(["id"]) +@Deserializable("Doc", fetchProto).withFields(["id"]) export class Doc extends RefField { constructor(id?: FieldId, forceSave?: boolean) { super(id); @@ -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; } |