diff options
-rw-r--r-- | .vscode/launch.json | 4 | ||||
-rw-r--r-- | src/client/DocServer.ts | 23 | ||||
-rw-r--r-- | src/client/util/SerializationHelper.ts | 5 |
3 files changed, 18 insertions, 14 deletions
diff --git a/.vscode/launch.json b/.vscode/launch.json index 822a06024..e4196600e 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -25,10 +25,6 @@ { "type": "chrome", "request": "launch", - "runtimeArgs": [ - "--enable-logging", - "--v=1" - ], "name": "Launch Chrome against Dash server", "sourceMaps": true, "breakOnLoad": true, diff --git a/src/client/DocServer.ts b/src/client/DocServer.ts index 258acd9cd..de9304858 100644 --- a/src/client/DocServer.ts +++ b/src/client/DocServer.ts @@ -124,16 +124,17 @@ export namespace DocServer { // future .proto calls on the Doc won't have to go farther than the cache to get their actual value. const deserializeField = getSerializedField.then(async fieldJson => { // deserialize - const field = await SerializationHelper.Deserialize(fieldJson); + const field = await SerializationHelper.Deserialize(fieldJson, val => { + if (val !== undefined) { + _cache[id] = field; + } else { + delete _cache[id]; + } + }); + return field; // either way, overwrite or delete any promises cached at this id (that we inserted as flags // to indicate that the field was in the process of being fetched). Now everything // should be an actual value within or entirely absent from the cache. - if (field !== undefined) { - _cache[id] = field; - } else { - delete _cache[id]; - } - return field; }); // here, indicate that the document associated with this id is currently // being retrieved and cached @@ -217,7 +218,13 @@ export namespace DocServer { for (const field of fields) { if (field !== undefined) { // deserialize - let deserialized = await SerializationHelper.Deserialize(field); + let deserialized = await SerializationHelper.Deserialize(field, val => { + if (val !== undefined) { + _cache[field.id] = field; + } else { + delete _cache[field.id]; + } + }); fieldMap[field.id] = deserialized; // adds to a list of promises that will be awaited asynchronously // protosToLoad.push(deserialized.proto); diff --git a/src/client/util/SerializationHelper.ts b/src/client/util/SerializationHelper.ts index 034be8f67..13302be21 100644 --- a/src/client/util/SerializationHelper.ts +++ b/src/client/util/SerializationHelper.ts @@ -1,6 +1,7 @@ import { PropSchema, serialize, deserialize, custom, setDefaultModelSchema, getDefaultModelSchema, primitive, SKIP } from "serializr"; import { Field, Doc } from "../../new_fields/Doc"; import { ClientUtils } from "./ClientUtils"; +import { emptyFunction } from "../../Utils"; let serializing = 0; export function afterDocDeserialize(cb: (err: any, val: any) => void, err: any, newValue: any) { @@ -33,7 +34,7 @@ export namespace SerializationHelper { return json; } - export async function Deserialize(obj: any): Promise<any> { + export async function Deserialize(obj: any, cb: (val: any) => void = emptyFunction): Promise<any> { if (obj === undefined || obj === null) { return undefined; } @@ -56,7 +57,7 @@ export namespace SerializationHelper { } const type = serializationTypes[obj.__type]; - const value = await new Promise(res => deserialize(type.ctor, obj, (err, result) => res(result))); + const value = await new Promise(res => cb(deserialize(type.ctor, obj, (err, result) => res(result)))); if (type.afterDeserialize) { await type.afterDeserialize(value); } |