aboutsummaryrefslogtreecommitdiff
path: root/src/fields/ScriptField.ts
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2022-03-07 12:14:39 -0500
committerbobzel <zzzman@gmail.com>2022-03-07 12:14:39 -0500
commitc21919a2105bd1ed4f060be149624d064739a36c (patch)
treee88bbc4db244a08bd759e2985a31593a4b521911 /src/fields/ScriptField.ts
parent7fa30c3edd851cc42cb68063d9dbdd7335fe7370 (diff)
got rid of include cycles for Scripting globals to make hot updates work better.
Diffstat (limited to 'src/fields/ScriptField.ts')
-rw-r--r--src/fields/ScriptField.ts31
1 files changed, 16 insertions, 15 deletions
diff --git a/src/fields/ScriptField.ts b/src/fields/ScriptField.ts
index 258348950..40ca0ce22 100644
--- a/src/fields/ScriptField.ts
+++ b/src/fields/ScriptField.ts
@@ -1,6 +1,7 @@
import { computedFn } from "mobx-utils";
import { createSimpleSchema, custom, map, object, primitive, PropSchema, serializable, SKIP } from "serializr";
-import { CompiledScript, CompileScript, Scripting, scriptingGlobal } from "../client/util/Scripting";
+import { CompiledScript, CompileScript } from "../client/util/Scripting";
+import { scriptingGlobal, ScriptingGlobals } from "../client/util/ScriptingGlobals";
import { autoObject, Deserializable } from "../client/util/SerializationHelper";
import { numberRange } from "../Utils";
import { Doc, Field, Opt } from "./Doc";
@@ -185,19 +186,6 @@ export class ComputedField extends ScriptField {
return getField.compiled ? new ComputedField(getField, setField?.compiled ? setField : undefined) : undefined;
}
}
-Scripting.addGlobal(function setIndexVal(list: any[], index: number, value: any) {
- while (list.length <= index) list.push(undefined);
- list[index] = value;
-}, "sets the value at a given index of a list", "(list: any[], index: number, value: any)");
-
-Scripting.addGlobal(function getIndexVal(list: any[], index: number) {
- return list?.reduce((p, x, i) => (i <= index && x !== undefined) || p === undefined ? x : p, undefined as any);
-}, "returns the value at a given index of a list", "(list: any[], index: number)");
-
-Scripting.addGlobal(function makeScript(script: string) {
- return ScriptField.MakeScript(script);
-}, "returns the value at a given index of a list", "(list: any[], index: number)");
-
export namespace ComputedField {
let useComputed = true;
export function DisableComputedFields() {
@@ -226,4 +214,17 @@ export namespace ComputedField {
}
});
}
-} \ No newline at end of file
+}
+
+ScriptingGlobals.add(function setIndexVal(list: any[], index: number, value: any) {
+ while (list.length <= index) list.push(undefined);
+ list[index] = value;
+}, "sets the value at a given index of a list", "(list: any[], index: number, value: any)");
+
+ScriptingGlobals.add(function getIndexVal(list: any[], index: number) {
+ return list?.reduce((p, x, i) => (i <= index && x !== undefined) || p === undefined ? x : p, undefined as any);
+}, "returns the value at a given index of a list", "(list: any[], index: number)");
+
+ScriptingGlobals.add(function makeScript(script: string) {
+ return ScriptField.MakeScript(script);
+}, "returns the value at a given index of a list", "(list: any[], index: number)");