aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2021-09-17 17:51:46 -0400
committerbobzel <zzzman@gmail.com>2021-09-17 17:51:46 -0400
commit385c635159bfa9bff86ddd6e46c96b934d2a9391 (patch)
tree302c833f762a68e573e38b8d33383206c967339d /src
parentb4a3dd6551a0ad6582c2a1a42168faae74ef1913 (diff)
fixed following links to documents in sidebars that haven't been opened to still open the sidebar and show the document. required a change to how ProxyFields set field promises and use field caches.
Diffstat (limited to 'src')
-rw-r--r--src/client/views/SidebarAnnos.tsx2
-rw-r--r--src/fields/Proxy.ts66
2 files changed, 11 insertions, 57 deletions
diff --git a/src/client/views/SidebarAnnos.tsx b/src/client/views/SidebarAnnos.tsx
index 659eb86d1..6a5b0a3ae 100644
--- a/src/client/views/SidebarAnnos.tsx
+++ b/src/client/views/SidebarAnnos.tsx
@@ -68,8 +68,8 @@ export class SidebarAnnos extends React.Component<FieldViewProps & ExtraProps> {
if (DocListCast(this.props.rootDoc[this.sidebarKey]).includes(doc)) {
if (this.props.layoutDoc[this.filtersKey]) {
this.props.layoutDoc[this.filtersKey] = new List<string>();
- return true;
}
+ return true;
}
return false;
}
diff --git a/src/fields/Proxy.ts b/src/fields/Proxy.ts
index 62734d3d2..07553f17c 100644
--- a/src/fields/Proxy.ts
+++ b/src/fields/Proxy.ts
@@ -9,72 +9,33 @@ import { Id, Copy, ToScriptString, ToString } from "./FieldSymbols";
import { scriptingGlobal } from "../client/util/Scripting";
import { Plugins } from "./util";
-function deserializeProxy(field: any) {
- if (!field.cache) {
- field.cache = DocServer.GetCachedRefField(field.fieldId) as any;
- }
-}
-@Deserializable("proxy", deserializeProxy)
+@Deserializable("proxy")
export class ProxyField<T extends RefField> extends ObjectField {
constructor();
constructor(value: T);
constructor(fieldId: string);
constructor(value?: T | string) {
super();
- if (typeof value === "string") {
- this.cache = DocServer.GetCachedRefField(value) as any;
- this.fieldId = value;
- } else if (value) {
- this.cache = value;
- this.fieldId = value[Id];
- }
- }
-
- [Copy]() {
- if (this.cache) return new ProxyField<T>(this.cache);
- return new ProxyField<T>(this.fieldId);
+ this.fieldId = typeof value === "string" ? value : (value?.[Id] ?? "");
}
- [ToScriptString]() {
- return "invalid";
- }
- [ToString]() {
- return "ProxyField";
- }
+ [Copy]() { return new ProxyField<T>((this.cache ?? this.fieldId) as T); }
+ [ToScriptString]() { return "invalid"; }
+ [ToString]() { return "ProxyField"; }
@serializable(primitive())
readonly fieldId: string = "";
-
- // This getter/setter and nested object thing is
- // because mobx doesn't play well with observable proxies
- @observable.ref
- private _cache: { readonly field: T | undefined } = { field: undefined };
- private get cache(): T | undefined {
- return this._cache.field;
- }
- private set cache(field: T | undefined) {
- this._cache = { field };
- }
-
private failed = false;
private promise?: Promise<any>;
+ private get cache(): T | undefined { return DocServer.GetCachedRefField(this.fieldId) as T }
+
value(): T | undefined | FieldWaiting<T> {
- if (this.cache) {
- return this.cache;
- }
- if (this.failed) {
- return undefined;
- }
+ if (this.cache) return this.cache;
+ if (this.failed) 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;
if (field === undefined) this.failed = true;
return field;
}));
@@ -83,14 +44,7 @@ export class ProxyField<T extends RefField> extends ObjectField {
}
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;
+ if (this.cache === undefined) this.promise = promise;
}
}