aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/KeyValueBox.tsx
diff options
context:
space:
mode:
authorFawn <fangrui_tong@brown.edu>2019-06-25 18:23:26 -0400
committerFawn <fangrui_tong@brown.edu>2019-06-25 18:23:26 -0400
commit7abe170ce5bd0c415e23456eb2bed26e8fdee7aa (patch)
treecc7bdf2859274b78fb8a803f746ec873b5c14a58 /src/client/views/nodes/KeyValueBox.tsx
parent41cf1e8536964764f18ab752140e484e36cbe464 (diff)
parent219cabb3fe42ab199550efc3423b7aaed4e1ee93 (diff)
merge
Diffstat (limited to 'src/client/views/nodes/KeyValueBox.tsx')
-rw-r--r--src/client/views/nodes/KeyValueBox.tsx8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/client/views/nodes/KeyValueBox.tsx b/src/client/views/nodes/KeyValueBox.tsx
index 917be734d..cd65c42bc 100644
--- a/src/client/views/nodes/KeyValueBox.tsx
+++ b/src/client/views/nodes/KeyValueBox.tsx
@@ -9,7 +9,7 @@ import { KeyValuePair } from "./KeyValuePair";
import React = require("react");
import { NumCast, Cast, FieldValue } from "../../../new_fields/Types";
import { Doc, Field } from "../../../new_fields/Doc";
-import { ComputedField } from "../../../fields/ScriptField";
+import { ComputedField } from "../../../new_fields/ScriptField";
@observer
export class KeyValueBox extends React.Component<FieldViewProps> {
@@ -38,10 +38,11 @@ export class KeyValueBox extends React.Component<FieldViewProps> {
}
public static SetField(doc: Doc, key: string, value: string) {
let eq = value.startsWith("=");
+ let target = eq ? doc : Doc.GetProto(doc);
value = eq ? value.substr(1) : value;
let dubEq = value.startsWith(":=");
value = dubEq ? value.substr(2) : value;
- let options: ScriptOptions = { addReturn: true };
+ let options: ScriptOptions = { addReturn: true, params: { this: "Doc" } };
if (dubEq) options.typecheck = false;
let script = CompileScript(value, options);
if (!script.compiled) {
@@ -49,12 +50,11 @@ export class KeyValueBox extends React.Component<FieldViewProps> {
}
let field = new ComputedField(script);
if (!dubEq) {
- let res = script.run();
+ let res = script.run({ this: target });
if (!res.success) return false;
field = res.result;
}
if (Field.IsField(field, true)) {
- let target = !eq ? doc : Doc.GetProto(doc);
target[key] = field;
return true;
}