diff options
author | Sam Wilkins <samwilkins333@gmail.com> | 2020-04-07 13:46:15 -0700 |
---|---|---|
committer | Sam Wilkins <samwilkins333@gmail.com> | 2020-04-07 13:46:15 -0700 |
commit | 52ad8b3874419a76e6953c3bd698d9e68a3158a6 (patch) | |
tree | a20156fa4453c817aa52d8d807dbc705066c5f6e /src/new_fields/ScriptField.ts | |
parent | edd96f6d78ff066f0a14efefaa92a9710caff9bd (diff) | |
parent | 9ad73769dd2f3a7c6598041f123dfd5cb7ef05d5 (diff) |
pulled
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 148886848..4a3119aeb 100644 --- a/src/new_fields/ScriptField.ts +++ b/src/new_fields/ScriptField.ts @@ -131,7 +131,8 @@ export class ScriptField extends ObjectField { export class ComputedField extends ScriptField { _lastComputedResult: any; //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 = computedFn((doc: Doc) => this._lastComputedResult = this.script.run({ this: doc, self: Cast(doc.rootDocument, Doc, null) || doc, _last_: this._lastComputedResult }, console.log).result); + value = computedFn((doc: Doc) => this._valueOutsideReaction(doc)); + _valueOutsideReaction = (doc: Doc) => this._lastComputedResult = this.script.run({ this: doc, self: Cast(doc.rootDocument, Doc, null) || doc, _last_: this._lastComputedResult }, console.log).result; public static MakeScript(script: string, params: object = {}) { const compiled = ScriptField.CompileScript(script, params, false); return compiled.compiled ? new ComputedField(compiled) : undefined; @@ -166,7 +167,7 @@ export namespace ComputedField { export function initPlugin() { Plugins.addGetterPlugin((doc, _, value) => { if (useComputed && value instanceof ComputedField) { - return { value: value.value(doc), shouldReturn: true }; + return { value: value._valueOutsideReaction(doc), shouldReturn: true }; } }); } |