aboutsummaryrefslogtreecommitdiff
path: root/src/new_fields/ScriptField.ts
diff options
context:
space:
mode:
authorBob Zeleznik <zzzman@gmail.com>2020-04-07 11:52:25 -0400
committerBob Zeleznik <zzzman@gmail.com>2020-04-07 11:52:25 -0400
commit892174ef482f3d45167a0c2d1c3163e6b9443c66 (patch)
tree6457eeb1db901920001ea6bf69e3bb8574fcde48 /src/new_fields/ScriptField.ts
parent8b02394f24e4f15674bf18192f49ee2385d67655 (diff)
got rid of some run-time errors/warnings related to CORS-ifying imagebox requests, and avoiding memoizing messages for computedFn's outside reactions.
Diffstat (limited to 'src/new_fields/ScriptField.ts')
-rw-r--r--src/new_fields/ScriptField.ts5
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 };
}
});
}