@@ -9,8 +9,6 @@ module Model = {
99 current: state ,
1010 undo_stack: list (Updated . t (state )),
1111 redo_stack: list (Updated . t (state )),
12- future_log: list ((float , Page . Update . t )),
13- replay_toggle: bool ,
1412 };
1513
1614 let equal = (=== );
@@ -19,8 +17,6 @@ module Model = {
1917 current: Page . Store . load() ,
2018 undo_stack: [] ,
2119 redo_stack: [] ,
22- future_log: [] ,
23- replay_toggle: false ,
2420 };
2521};
2622
@@ -30,15 +26,6 @@ module Update = {
3026 [@ deriving (show({with_path: false }), sexp, yojson)]
3127 type t = Page . Update . t ;
3228
33- // let sexp = Page.Update.sexp_of_t(action);
34- // For now, we don't ignore any actions; add here if needed
35- // check if str contains "(Select (Term (Id" (ignoring whitespace)
36- // let str = Sexplib.Sexp.to_string(sexp);
37- // StringUtil.match(StringUtil.regexp("Select\\s*\\(Term\\s*\\(Id"), str);
38- let ignore_if_action_fails_in_log_replay = (_action: t ): bool => {
39- false ;
40- };
41-
4229 [@ deriving (show({with_path: false }), sexp, yojson)]
4330 let update =
4431 (
@@ -55,13 +42,10 @@ module Update = {
5542 | [] =>
5643 print_endline("Cannot undo" );
5744 model |> Updated . raise_invalid_action;
58- | [ x , ... rest ] =>
59- Log . Entry . save(Log . Entry . mk(action));
60- {
45+ | [ x , ... rest ] => {
6146 ... x,
6247 model: {
6348 current: x. model,
64- future_log: model. future_log,
6549 undo_stack: rest,
6650 redo_stack: [
6751 {
@@ -70,22 +54,18 @@ module Update = {
7054 },
7155 ... model. redo_stack,
7256 ] ,
73- replay_toggle: model. replay_toggle,
7457 },
75- };
58+ }
7659 }
7760 | Globals (Redo ) =>
7861 switch (model. redo_stack) {
7962 | [] =>
8063 print_endline("Cannot redo" );
8164 model |> Updated . raise_invalid_action;
82- | [ x , ... rest ] =>
83- Log . Entry . save(Log . Entry . mk(action));
84- {
65+ | [ x , ... rest ] => {
8566 ... x,
8667 model: {
8768 current: x. model,
88- future_log: model. future_log,
8969 undo_stack: [
9070 {
9171 ... x,
@@ -94,135 +74,8 @@ module Update = {
9474 ... model. undo_stack,
9575 ] ,
9676 redo_stack: rest,
97- replay_toggle: model. replay_toggle,
9877 },
99- };
100- }
101- | Globals (Log (a )) =>
102- switch (a) {
103- | InitImport (f ) =>
104- JsUtil . read_file(f, data =>
105- schedule_action(Globals (Log (FinishImport (data))))
106- );
107- model |> Updated . return_quiet;
108- | FinishImport (None ) =>
109- LogSidebar . log_error("Log import failed" );
110- model |> Updated . return_quiet;
111- | FinishImport (Some (data )) =>
112- let of_data = (data: string ): list((float, Page . Update . t)) =>
113- Export . import_just_log(data)
114- |> Sexplib . Sexp . of_string
115- |> Log . Entry . s_of_sexp_opt
116- |> List . filter_map(x => x);
117- let actions =
118- data
119- |> of_data
120- |> Log . flatten_imports(~of_data)
121- |> (
122- x => {
123- LogSidebar . log_info(
124- "Imported log entries: " ++ string_of_int(List . length(x)),
125- );
126- x;
127- }
128- );
129- {
130- ... model,
131- future_log: model. future_log @ actions,
132- }
133- |> Updated . return_quiet;
134- | NextLog =>
135- switch (model. future_log) {
136- | [] =>
137- LogSidebar . log_info("No next log action to perform" );
138- model |> Updated . return_quiet;
139- | [ (t , next ), ... rest ] =>
140- LogSidebar . log_action(
141- "Applying next log action" ,
142- Some (JsUtil . print_timestamp(t)),
143- );
144- // Keep full action expression in console for detailed debugging
145- print_endline("Full action: " ++ Page . Update . show(next));
146- try ({
147- let updated =
148- Page . Update . update(
149- ~import_log,
150- ~get_log_and,
151- ~schedule_action,
152- next,
153- model. current,
154- );
155- {
156- ... updated,
157- model: {
158- current: updated. model,
159- undo_stack: [
160- {
161- ... updated,
162- model: model. current,
163- },
164- ... model. undo_stack,
165- ] ,
166- redo_stack: model. redo_stack,
167- future_log: rest,
168- replay_toggle: model. replay_toggle,
169- },
170- };
171- }) {
172- | _ =>
173- LogSidebar . log_error("Failed to apply log action" );
174- Model . {
175- ... model,
176- future_log:
177- ignore_if_action_fails_in_log_replay(next)
178- ? rest : model. future_log,
179- replay_toggle:
180- ignore_if_action_fails_in_log_replay(next)
181- ? model. replay_toggle : false ,
182- }
183- |> Updated . return_quiet;
184- };
185- }
186- | SkipLog =>
187- LogSidebar . log_action("Skipping the next log entry" , None );
188- switch (model. future_log) {
189- | [] =>
190- LogSidebar . log_info("No log entry to skip" );
191- model |> return_quiet;
192- | [ (_ , _ ), ... rest ] =>
193- {
194- ... model,
195- future_log: rest,
196- }
197- |> return_quiet
198- };
199- | SkipExercise =>
200- LogSidebar . log_action(
201- "Skipping to the next exercise in the log" ,
202- None ,
203- );
204- let rec skip_to_next_exercise = (log: list ((float , Page . Update . t ))) =>
205- switch (log) {
206- | [] => []
207- | [ (_ , Editors (SwitchMode (_ ))), ... _ ] as rest => rest
208- | [ (_ , Editors (Exercises (SwitchExercise (_ )))), ... _ ] as rest => rest
209- | [ (_ , _ ), ... rest ] => skip_to_next_exercise(rest)
210- };
211- {
212- ... model,
213- future_log: skip_to_next_exercise(model. future_log),
214- }
215- |> return_quiet;
216- | ToggleReplay =>
217- Model . {
218- ... model,
219- replay_toggle: ! model. replay_toggle,
22078 }
221- |> return_quiet
222- | ClearLog =>
223- Log . DB . clear_and(() => () );
224- LogSidebar . log_info("Log cleared" );
225- model |> return_quiet;
22679 }
22780 | action =>
22881 let current =
@@ -233,13 +86,11 @@ module Update = {
23386 action,
23487 model. current,
23588 );
236- let _ = Log . update(action, current);
23789 if (Page . Update . can_undo(action)) {
23890 {
23991 ... current,
24092 model: {
24193 current: current. model,
242- future_log: model. future_log,
24394 undo_stack: [
24495 {
24596 ... current,
@@ -248,7 +99,6 @@ module Update = {
24899 ... model. undo_stack,
249100 ] ,
250101 redo_stack: [] ,
251- replay_toggle: model. replay_toggle,
252102 },
253103 };
254104 } else {
@@ -258,8 +108,6 @@ module Update = {
258108 current: current. model,
259109 undo_stack: model. undo_stack,
260110 redo_stack: model. redo_stack,
261- future_log: model. future_log,
262- replay_toggle: model. replay_toggle,
263111 },
264112 };
265113 };
@@ -278,8 +126,6 @@ module Update = {
278126 |> Page . Update . calculate(~schedule_action, ~is_edited, ~dynamics),
279127 undo_stack: model. undo_stack,
280128 redo_stack: model. redo_stack,
281- future_log: model. future_log,
282- replay_toggle: model. replay_toggle,
283129 };
284130};
285131
0 commit comments