aboutsummaryrefslogtreecommitdiff
path: root/src/new_fields/Proxy.ts
diff options
context:
space:
mode:
authorAbdullah Ahmed <abdullah_ahmed@brown.edu>2019-08-13 11:02:45 -0400
committerAbdullah Ahmed <abdullah_ahmed@brown.edu>2019-08-13 11:02:45 -0400
commit6c8b7a4e74068178b0f6ca9e491441bf982b4622 (patch)
treecc52f43409819694359d5fcd07f6f01cbd39dea1 /src/new_fields/Proxy.ts
parentb38e808dc7790cc8698824329ae63b3af210996c (diff)
parent9dd2a31b72e5e527e2dae3b68f856ab8da879e93 (diff)
Merge branch 'recommender_system' of https://github.com/browngraphicslab/Dash-Web into recommender_system
Diffstat (limited to 'src/new_fields/Proxy.ts')
-rw-r--r--src/new_fields/Proxy.ts29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/new_fields/Proxy.ts b/src/new_fields/Proxy.ts
index b3e8d6467..c6292e37c 100644
--- a/src/new_fields/Proxy.ts
+++ b/src/new_fields/Proxy.ts
@@ -7,6 +7,7 @@ import { RefField } from "./RefField";
import { ObjectField } from "./ObjectField";
import { Id, Copy, ToScriptString } from "./FieldSymbols";
import { scriptingGlobal } from "../client/util/Scripting";
+import { Plugins } from "./util";
@Deserializable("proxy")
export class ProxyField<T extends RefField> extends ObjectField {
@@ -68,6 +69,34 @@ export class ProxyField<T extends RefField> extends ObjectField {
}
}
+export namespace ProxyField {
+ let useProxy = true;
+ export function DisableProxyFields() {
+ useProxy = false;
+ }
+
+ export function EnableProxyFields() {
+ useProxy = true;
+ }
+
+ export function WithoutProxy<T>(fn: () => T) {
+ DisableProxyFields();
+ try {
+ return fn();
+ } finally {
+ EnableProxyFields();
+ }
+ }
+
+ export function initPlugin() {
+ Plugins.addGetterPlugin((doc, _, value) => {
+ if (useProxy && value instanceof ProxyField) {
+ return { value: value.value() };
+ }
+ });
+ }
+}
+
function prefetchValue(proxy: PrefetchProxy<RefField>) {
return proxy.value() as any;
}