diff options
author | bob <bcz@cs.brown.edu> | 2019-07-19 14:43:26 -0400 |
---|---|---|
committer | bob <bcz@cs.brown.edu> | 2019-07-19 14:43:26 -0400 |
commit | 89b2500e71e4d167c7ae179c3eb2b5052b128ad0 (patch) | |
tree | 8b243d52a47024b06d9941134d56c4e25f80d930 /src/new_fields/ScriptField.ts | |
parent | ae07ba8fb410752ea98702219247ce5f89d1758b (diff) | |
parent | 8854d3277541a67aef4187b5d3592bea5a7fcfa2 (diff) |
Merge branch 'master' into stackingSections
Diffstat (limited to 'src/new_fields/ScriptField.ts')
-rw-r--r-- | src/new_fields/ScriptField.ts | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/new_fields/ScriptField.ts b/src/new_fields/ScriptField.ts index e2994ed70..b5b1595cf 100644 --- a/src/new_fields/ScriptField.ts +++ b/src/new_fields/ScriptField.ts @@ -4,6 +4,7 @@ import { Copy, ToScriptString, Parent, SelfProxy } from "./FieldSymbols"; import { serializable, createSimpleSchema, map, primitive, object, deserialize, PropSchema, custom, SKIP } from "serializr"; import { Deserializable } from "../client/util/SerializationHelper"; import { Doc } from "../new_fields/Doc"; +import { Plugins } from "./util"; function optional(propSchema: PropSchema) { return custom(value => { @@ -93,4 +94,30 @@ export class ComputedField extends ScriptField { } return undefined; } +} + +export namespace ComputedField { + let useComputed = true; + export function DisableComputedFields() { + useComputed = false; + } + + export function EnableComputedFields() { + useComputed = true; + } + + export function WithoutComputed<T>(fn: () => T) { + DisableComputedFields(); + try { + return fn(); + } finally { + EnableComputedFields(); + } + } + + Plugins.addGetterPlugin((doc, _, value) => { + if (useComputed && value instanceof ComputedField) { + return { value: value.value(doc), shouldReturn: true }; + } + }); }
\ No newline at end of file |