aboutsummaryrefslogtreecommitdiff
path: root/src/client/util/Scripting.ts
diff options
context:
space:
mode:
authorbob <bcz@cs.brown.edu>2019-06-25 09:09:28 -0400
committerbob <bcz@cs.brown.edu>2019-06-25 09:09:28 -0400
commit66acf0237f2e1fe74660e5c2a035757403f79f8b (patch)
treea4fa797203ee262072c53ba845e6bcce214f151e /src/client/util/Scripting.ts
parent038819c6f1490bfa3ef9a5a7404ea8688f2b9fd6 (diff)
parent45dee8324dc360953c584ba18f5b53220ecfdf61 (diff)
Merge branch 'templatesMac' of https://github.com/browngraphicslab/Dash-Web into templatesMac
Diffstat (limited to 'src/client/util/Scripting.ts')
-rw-r--r--src/client/util/Scripting.ts14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/client/util/Scripting.ts b/src/client/util/Scripting.ts
index 40e2ad6bb..30a05154a 100644
--- a/src/client/util/Scripting.ts
+++ b/src/client/util/Scripting.ts
@@ -12,7 +12,7 @@ import { Doc, Field } from '../../new_fields/Doc';
import { ImageField, PdfField, VideoField, AudioField } from '../../new_fields/URLField';
import { List } from '../../new_fields/List';
import { RichTextField } from '../../new_fields/RichTextField';
-import { ScriptField, ComputedField } from '../../fields/ScriptField';
+import { ScriptField, ComputedField } from '../../new_fields/ScriptField';
export interface ScriptSucccess {
success: true;
@@ -39,7 +39,6 @@ export interface CompileError {
}
export type CompileResult = CompiledScript | CompileError;
-
function Run(script: string | undefined, customParams: string[], diagnostics: any[], originalScript: string, options: ScriptOptions): CompileResult {
const errors = diagnostics.some(diag => diag.category === ts.DiagnosticCategory.Error);
if ((options.typecheck !== false && errors) || !script) {
@@ -64,10 +63,20 @@ function Run(script: string | undefined, customParams: string[], diagnostics: an
}
}
let thisParam = args.this || capturedVariables.this;
+ let batch: { end(): void } | undefined = undefined;
try {
+ if (!options.editable) {
+ batch = Doc.MakeReadOnly();
+ }
const result = compiledFunction.apply(thisParam, params).apply(thisParam, argsArray);
+ if (batch) {
+ batch.end();
+ }
return { success: true, result };
} catch (error) {
+ if (batch) {
+ batch.end();
+ }
return { success: false, error };
}
};
@@ -133,6 +142,7 @@ export interface ScriptOptions {
params?: { [name: string]: string };
capturedVariables?: { [name: string]: Field };
typecheck?: boolean;
+ editable?: boolean;
}
export function CompileScript(script: string, options: ScriptOptions = {}): CompileResult {