diff options
author | yipstanley <stanley_yip@brown.edu> | 2019-07-22 17:16:41 -0400 |
---|---|---|
committer | yipstanley <stanley_yip@brown.edu> | 2019-07-22 17:16:41 -0400 |
commit | 4d6aee4230e60b67ba62609ef543845c230ce739 (patch) | |
tree | 31af1ba8650bb9b0486d2dd86b41c88ed43aa829 /src/new_fields/ScriptField.ts | |
parent | 5e9bcf2e35415fd0ab4dec4f0141511cd4d312d0 (diff) | |
parent | fc1dbb1327d10bd1832d33a87d18cff1e836ecfb (diff) |
merge from master
Diffstat (limited to 'src/new_fields/ScriptField.ts')
-rw-r--r-- | src/new_fields/ScriptField.ts | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/new_fields/ScriptField.ts b/src/new_fields/ScriptField.ts index b5b1595cf..e8a1ea28a 100644 --- a/src/new_fields/ScriptField.ts +++ b/src/new_fields/ScriptField.ts @@ -5,6 +5,7 @@ import { serializable, createSimpleSchema, map, primitive, object, deserialize, import { Deserializable } from "../client/util/SerializationHelper"; import { Doc } from "../new_fields/Doc"; import { Plugins } from "./util"; +import { computedFn } from "mobx-utils"; function optional(propSchema: PropSchema) { return custom(value => { @@ -87,13 +88,13 @@ export class ScriptField extends ObjectField { @Deserializable("computed", deserializeScript) export class ComputedField extends ScriptField { //TODO maybe add an observable cache based on what is passed in for doc, considering there shouldn't really be that many possible values for doc - value(doc: Doc) { + value = computedFn((doc: Doc) => { const val = this.script.run({ this: doc }); if (val.success) { return val.result; } return undefined; - } + }); } export namespace ComputedField { |