diff options
| author | Andy Rickert <andrew_rickert@brown.edu> | 2020-05-12 17:37:54 -0700 |
|---|---|---|
| committer | Andy Rickert <andrew_rickert@brown.edu> | 2020-05-12 17:37:54 -0700 |
| commit | 9ad062907d38a7a853ba89fa31433380ae3cd7b3 (patch) | |
| tree | 707855e1bc6fa8ac3d1f51447815a51eb83b8aa3 /src/new_fields/Proxy.ts | |
| parent | 1848c78f889470d6c558f709efe1b521402b2793 (diff) | |
| parent | 4bd011dcc6a3f009fa10932c7c6ca1932b784fde (diff) | |
merge
Diffstat (limited to 'src/new_fields/Proxy.ts')
| -rw-r--r-- | src/new_fields/Proxy.ts | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/new_fields/Proxy.ts b/src/new_fields/Proxy.ts index d50c0f14e..555faaad0 100644 --- a/src/new_fields/Proxy.ts +++ b/src/new_fields/Proxy.ts @@ -1,7 +1,7 @@ import { Deserializable } from "../client/util/SerializationHelper"; import { FieldWaiting } from "./Doc"; import { primitive, serializable } from "serializr"; -import { observable, action } from "mobx"; +import { observable, action, runInAction } from "mobx"; import { DocServer } from "../client/DocServer"; import { RefField } from "./RefField"; import { ObjectField } from "./ObjectField"; @@ -61,6 +61,11 @@ export class ProxyField<T extends RefField> extends ObjectField { return undefined; } if (!this.promise) { + const cached = DocServer.GetCachedRefField(this.fieldId); + if (cached !== undefined) { + runInAction(() => this.cache = cached as any); + return cached as any; + } this.promise = DocServer.GetRefField(this.fieldId).then(action((field: any) => { this.promise = undefined; this.cache = field; @@ -70,6 +75,17 @@ export class ProxyField<T extends RefField> extends ObjectField { } return this.promise as any; } + promisedValue(): string { return !this.cache && !this.failed && !this.promise ? this.fieldId : ""; } + setPromise(promise: any) { + this.promise = promise; + } + @action + setValue(field: any) { + this.promise = undefined; + this.cache = field; + if (field === undefined) this.failed = true; + return field; + } } export namespace ProxyField { |
