diff options
| author | andrewdkim <adkim414@gmail.com> | 2019-08-06 12:30:09 -0400 |
|---|---|---|
| committer | andrewdkim <adkim414@gmail.com> | 2019-08-06 12:30:09 -0400 |
| commit | b6990a61befdea70abd99f125a2488ce5a6f04a6 (patch) | |
| tree | 833c13a0ddabb325cc2e39dbb199f111cced22d2 /src/new_fields/Proxy.ts | |
| parent | 2c86a6958186c020ce7fbe99555f07ffe9f9f821 (diff) | |
| parent | 298d1c9b29d6ce2171fd9ac8274b64583b73f6f5 (diff) | |
merge from master
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; } |
