diff options
author | monikahedman <monika_hedman@brown.edu> | 2019-08-08 15:03:03 -0400 |
---|---|---|
committer | monikahedman <monika_hedman@brown.edu> | 2019-08-08 15:03:03 -0400 |
commit | 8f951d9110d096d665af6fbd295902ef8d3574e8 (patch) | |
tree | 37cc6881cbf93aeea5deae53a6415d6607377edc /src/new_fields/Proxy.ts | |
parent | 030af1b9112cd12383abcd7f35142cc382ea4d6a (diff) | |
parent | 316c241d72fb83aad5f2bf9b143c317fdc906654 (diff) |
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web into checkbox
Diffstat (limited to 'src/new_fields/Proxy.ts')
-rw-r--r-- | src/new_fields/Proxy.ts | 29 |
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; } |