diff options
| author | Sam Wilkins <samwilkins333@gmail.com> | 2019-08-04 03:33:00 -0400 |
|---|---|---|
| committer | Sam Wilkins <samwilkins333@gmail.com> | 2019-08-04 03:33:00 -0400 |
| commit | 5a17fc9ff91e5a039a0ada4be498d8353ee94205 (patch) | |
| tree | f35c1fa99217198523e446ca3732f5a93dbf982c /src/new_fields/Proxy.ts | |
| parent | 8d6620dd6818c82363ec0c4d49a92b0e2c0c1036 (diff) | |
| parent | 02346eabdefd428ca23d6a3fbefdcd51ef62b738 (diff) | |
merged with 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; } |
