Skip to content

Commit

Permalink
client: Fix blocks executing order
Browse files Browse the repository at this point in the history
Belt.Map doesn't reserve order
So the blocks execution failing
seems to be random because the generated block ids are random

This fixes #68
  • Loading branch information
thangngoc89 committed Aug 10, 2018
1 parent 62b77d8 commit ec217a0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
12 changes: 9 additions & 3 deletions client/src_analyzer/Worker_Analyze.re
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,16 @@ module Make = (ESig: Worker_Evaluator.EvaluatorSig) => {
};

let executeMany:
(. Belt.Map.String.t(string)) => Belt.Map.String.t(list(blockData)) =
(. codeMap) => {
(. list((string, string))) => list((string, list(blockData))) =
(. codeBlocks) => {
/* Reset before evaluating several blocks */
Evaluator.reset();
codeMap->(Belt.Map.String.map(code => execute(. false, code)));
codeBlocks
->(
Belt.List.mapU((. (id, code)) => {
Js.log(code);
(id, execute(. false, code));
})
);
};
};
13 changes: 6 additions & 7 deletions client/src_editor/Editor_Blocks.re
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,17 @@ let make =
),
})
| Block_Execute =>
module MS = Belt.Map.String;

let allCodeBlocks =
state.blocks
->(
Belt.Array.reduceU(MS.empty, (. map, {b_id, b_data}) =>
Belt.Array.reduceU([], (. acc, {b_id, b_data}) =>
switch (b_data) {
| B_Text(_) => map
| B_Code({bc_value}) => map->(MS.set(b_id, bc_value))
| B_Text(_) => acc
| B_Code({bc_value}) => [(b_id, bc_value), ...acc]
}
)
);
)
->Belt.List.reverse;

/* Clear all widgets and execute all blocks */
ReasonReact.SideEffects(
Expand All @@ -133,7 +132,7 @@ let make =
|> then_(results => {
results
->(
MS.forEachU((. blockId, result) => {
Belt.List.forEachU((. (blockId, result)) => {
let widgets =
Editor_Blocks_Utils.executeResultToWidget(result);
self.send(Block_AddWidgets(blockId, widgets));
Expand Down
4 changes: 2 additions & 2 deletions client/src_editor/Editor_Worker.re
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ type js_executeResult = {
type rtop = {
execute: (. bool, string) => Js.Promise.t(list(Worker_Types.blockData)),
executeMany:
(. Belt.Map.String.t(string)) =>
Js.Promise.t(Belt.Map.String.t(list(Worker_Types.blockData))),
(. list((string, string))) =>
Js.Promise.t(list((string, list(Worker_Types.blockData)))),
};
let worker = RtopWorker.make();

Expand Down

0 comments on commit ec217a0

Please sign in to comment.