Skip to content

Commit d3015a6

Browse files
update temporaryStateComp setValue, setIn functions to return value in promise
1 parent e0383d8 commit d3015a6

File tree

1 file changed

+32
-25
lines changed

1 file changed

+32
-25
lines changed

client/packages/lowcoder/src/comps/comps/temporaryStateComp.tsx

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ import { JSONObject } from "util/jsonTypes";
1414
import { QueryTutorials } from "util/tutorialUtils";
1515
import { SimpleNameComp } from "./simpleNameComp";
1616
import { markdownCompCss, TacoMarkDown } from "lowcoder-design";
17+
import { evalAndReduce } from "../utils";
1718

1819
const TemporaryStateItemCompBase = new MultiCompBuilder(
19-
{
20-
name: SimpleNameComp,
21-
value: jsonValueStateControl(null),
22-
},
23-
() => null
24-
)
20+
{
21+
name: SimpleNameComp,
22+
value: jsonValueStateControl(null),
23+
},
24+
() => null
25+
)
2526
.setPropertyViewFn((children) => {
2627
return (
2728
<BottomTabs
@@ -80,7 +81,10 @@ const TemporaryStateItemCompWithMethodExpose = withMethodExposing(TemporaryState
8081
description: "",
8182
},
8283
execute: async (comp, params) => {
83-
comp.children.value.change(params?.[0]);
84+
return new Promise(async (resolve) => {
85+
await comp.children.value.change(params?.[0]);
86+
resolve(params?.[0])
87+
})
8488
},
8589
},
8690
{
@@ -99,24 +103,27 @@ const TemporaryStateItemCompWithMethodExpose = withMethodExposing(TemporaryState
99103
description: "",
100104
},
101105
execute: async (comp, params) => {
102-
const { value: prev, onChange } = comp.children.value.getView();
103-
const [path, value] = params;
104-
if (
105-
!Array.isArray(path) ||
106-
!path.every((i) => typeof i === "string" || typeof i === "number")
107-
) {
108-
throw new Error(trans("temporaryState.pathTypeError"));
109-
}
110-
if (!_.isPlainObject(prev) && !Array.isArray(prev)) {
111-
throw new Error(
112-
trans("temporaryState.unStructuredError", {
113-
path: JSON.stringify(path),
114-
prev: JSON.stringify(prev),
115-
})
116-
);
117-
}
118-
const nextValue = _.set(_.cloneDeep(prev as JSONObject), path as (string | number)[], value);
119-
onChange(nextValue);
106+
return new Promise(async (resolve) => {
107+
const { value: prev, onChange } = comp.children.value.getView();
108+
const [path, value] = params;
109+
if (
110+
!Array.isArray(path) ||
111+
!path.every((i) => typeof i === "string" || typeof i === "number")
112+
) {
113+
throw new Error(trans("temporaryState.pathTypeError"));
114+
}
115+
if (!_.isPlainObject(prev) && !Array.isArray(prev)) {
116+
throw new Error(
117+
trans("temporaryState.unStructuredError", {
118+
path: JSON.stringify(path),
119+
prev: JSON.stringify(prev),
120+
})
121+
);
122+
}
123+
const nextValue = _.set(_.cloneDeep(prev as JSONObject), path as (string | number)[], value);
124+
await onChange(nextValue);
125+
resolve(nextValue);
126+
})
120127
},
121128
},
122129
]);

0 commit comments

Comments
 (0)