aboutsummaryrefslogtreecommitdiff
path: root/src/new_fields
diff options
context:
space:
mode:
Diffstat (limited to 'src/new_fields')
-rw-r--r--src/new_fields/Doc.ts6
-rw-r--r--src/new_fields/ScriptField.ts5
2 files changed, 4 insertions, 7 deletions
diff --git a/src/new_fields/Doc.ts b/src/new_fields/Doc.ts
index 0859cf41a..b875e7896 100644
--- a/src/new_fields/Doc.ts
+++ b/src/new_fields/Doc.ts
@@ -382,13 +382,13 @@ export namespace Doc {
}
//
- // Resolves a reference to a field by returning 'doc' if field extension is specified,
+ // Resolves a reference to a field by returning 'doc' if no field extension is specified,
// otherwise, it returns the extension document stored in doc.<fieldKey>_ext.
// This mechanism allows any fields to be extended with an extension document that can
// be used to capture field-specific metadata. For example, an image field can be extended
// to store annotations, ink, and other data.
//
- export function resolvedFieldDataDoc(doc: Doc, fieldKey: string, fieldExt: string) {
+ export function fieldExtensionDoc(doc: Doc, fieldKey: string, fieldExt: string = "yes") {
return fieldExt && doc[fieldKey + "_ext"] instanceof Doc ? doc[fieldKey + "_ext"] as Doc : doc;
}
@@ -477,7 +477,7 @@ export namespace Doc {
let resolvedDataDoc = !doc.isTemplate && dataDoc !== doc && dataDoc ? Doc.GetDataDoc(dataDoc) : undefined;
if (resolvedDataDoc && Doc.WillExpandTemplateLayout(childDocLayout, resolvedDataDoc)) {
Doc.UpdateDocumentExtensionForField(resolvedDataDoc, fieldKey);
- let fieldExtensionDoc = Doc.resolvedFieldDataDoc(resolvedDataDoc, StrCast(childDocLayout.templateField, StrCast(childDocLayout.title)), "dummy");
+ let fieldExtensionDoc = Doc.fieldExtensionDoc(resolvedDataDoc, StrCast(childDocLayout.templateField, StrCast(childDocLayout.title)), "dummy");
layoutDoc = Doc.expandTemplateLayout(childDocLayout, fieldExtensionDoc !== resolvedDataDoc ? fieldExtensionDoc : undefined);
} else layoutDoc = Doc.expandTemplateLayout(childDocLayout, resolvedDataDoc);
return { layout: layoutDoc, data: resolvedDataDoc };
diff --git a/src/new_fields/ScriptField.ts b/src/new_fields/ScriptField.ts
index 8f10766df..cdc9871a8 100644
--- a/src/new_fields/ScriptField.ts
+++ b/src/new_fields/ScriptField.ts
@@ -125,10 +125,7 @@ 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 = computedFn((doc: Doc) => {
- const val = this.script.run({ this: doc });
- return val.success ? val.result : undefined;
- });
+ value = computedFn((doc: Doc) => this.script.run({ this: doc }, console.log).result);
public static MakeScript(script: string, params: object = {}, ) {
let compiled = ScriptField.CompileScript(script, params, false);
return compiled.compiled ? new ComputedField(compiled) : undefined;