diff options
| author | bobzel <zzzman@gmail.com> | 2019-09-20 15:11:30 -0400 |
|---|---|---|
| committer | bobzel <zzzman@gmail.com> | 2019-09-20 15:11:30 -0400 |
| commit | 6f7936d5c71bf3c802d73f47b19abe96c6d61848 (patch) | |
| tree | 266d2f5f47bdde960656a5a14888b7bba09fac62 /src/new_fields | |
| parent | 2a003f69f8b5323c2a6b244332b1511df1ef0cc1 (diff) | |
simplified script execution api a little. fixed dataDoc() related stuff in various Box's. fixed some template stuff.
Diffstat (limited to 'src/new_fields')
| -rw-r--r-- | src/new_fields/Doc.ts | 6 | ||||
| -rw-r--r-- | src/new_fields/ScriptField.ts | 5 |
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; |
