From 44aa6fe49de97998fd84a6d6331501c8a1d7a775 Mon Sep 17 00:00:00 2001 From: Tyler Schicke Date: Sun, 7 Apr 2019 01:14:31 -0400 Subject: Refactored scripting to seperate compilation and execution --- src/client/views/collections/CollectionSchemaView.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/client/views/collections') diff --git a/src/client/views/collections/CollectionSchemaView.tsx b/src/client/views/collections/CollectionSchemaView.tsx index 0ff6c3b40..afe530c1a 100644 --- a/src/client/views/collections/CollectionSchemaView.tsx +++ b/src/client/views/collections/CollectionSchemaView.tsx @@ -87,11 +87,13 @@ export class CollectionSchemaView extends CollectionViewBase { let reference = React.createRef(); let onItemDown = setupDrag(reference, () => props.doc, (containingCollection: CollectionView) => this.props.removeDocument(props.doc)); let applyToDoc = (doc: Document, value: string) => { - let script = CompileScript(value, { this: doc }, true); + let script = CompileScript(value, { addReturn: true, params: { this: "Document" } }); if (!script.compiled) { return false; } - let field = script(); + const res = script.run({ this: doc }); + if (!res.success) return false; + const field = res.result; if (field instanceof Field) { doc.Set(props.fieldKey, field); return true; @@ -121,6 +123,7 @@ export class CollectionSchemaView extends CollectionViewBase { return applyToDoc(props.doc, value); }} OnFillDown={(value: string) => { + //TODO This should be able to be refactored to compile the script once this.props.Document.GetTAsync>(this.props.fieldKey, ListField).then((val) => { if (val) { val.Data.forEach(doc => applyToDoc(doc, value)); -- cgit v1.2.3-70-g09d2