aboutsummaryrefslogtreecommitdiff
path: root/src/fields/ScriptField.ts
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2024-03-28 11:38:56 -0400
committerbobzel <zzzman@gmail.com>2024-03-28 11:38:56 -0400
commit1b592f74a7df8f6dd7b2881032725f26aedff403 (patch)
tree900179f9218af09932b061b55c5153fa9575f13e /src/fields/ScriptField.ts
parent52bd492747cf169df7bcdecdbdbb353d45b19734 (diff)
fixed keyvaluebox to show props document, never the doc in the fieldKey slot. changed computedFIelds to do mobx caching. changed text boxes to do updating from templates based on a fieldKey_autoUpdate flag combined with modification timestamps. enabled comparison box to work with text fields in addition to docs.
Diffstat (limited to 'src/fields/ScriptField.ts')
-rw-r--r--src/fields/ScriptField.ts22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/fields/ScriptField.ts b/src/fields/ScriptField.ts
index 9021c8896..8b51088b2 100644
--- a/src/fields/ScriptField.ts
+++ b/src/fields/ScriptField.ts
@@ -198,14 +198,22 @@ export class ComputedField extends ScriptField {
}
_lastComputedResult: FieldResult;
- value = computedFn((doc: Doc) => this._valueOutsideReaction(doc));
- _valueOutsideReaction = (doc: Doc) => {
- this._lastComputedResult =
- this._cachedResult ?? (this.script.compiled && this.script.run({ this: doc, self: doc, value: '', _setCacheResult_: this.setCacheResult, _last_: this._lastComputedResult, _readOnly_: true }, console.log).result);
- return this._lastComputedResult;
- };
+ value = (doc:Doc) => (this._lastComputedResult = this._cachedResult ??
+ computedFn((doc: Doc) =>
+ this.script.compiled &&
+ this.script.run( {
+ this: doc,
+ //value: '',
+ _setCacheResult_: this.setCacheResult,
+ _last_: this._lastComputedResult,
+ _readOnly_: true,
+ },
+ console.log
+ ).result
+ )(doc)
+ ); // prettier-ignore
- [ToValue](doc: Doc) { if (ComputedField.useComputed) return { value: this._valueOutsideReaction(doc) }; } // prettier-ignore
+ [ToValue](doc: Doc) { if (ComputedField.useComputed) return { value: this.value(doc) }; } // prettier-ignore
[Copy](): ObjectField { return new ComputedField(this.script, this.setterscript, this.rawscript); } // prettier-ignore
public static MakeFunction(script: string, params: object = {}, capturedVariables?: { [name: string]: Doc | string | number | boolean }, setterscript?: string) {