Skip to content

Commit

Permalink
on_startup first attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
Negabinary committed Sep 26, 2024
1 parent 9171acb commit 2e2aa4c
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/haz3lweb/Main.re
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,8 @@ let apply = (model, action, ~schedule_action): Model.t => {
};

let on_startup =
(
~inject: UpdateAction.t => Ui_effect.t(unit),
~schedule_event: Ui_effect.t(unit) => unit,
m: Model.t,
)
: Model.t => {
let schedule_action = action => schedule_event(inject(action));
(~inject: UpdateAction.t => Ui_effect.t(unit), m: Model.t)
: Ui_effect.t(unit) => {
let _ =
observe_font_specimen("font-specimen", fm =>
schedule_action(Haz3lweb.Update.SetMeta(FontMetrics(fm)))
Expand All @@ -91,7 +86,7 @@ let on_startup =
Js.string("MAC"),
)
>= 0;
m;
Ui_effect.Ignore;
};

module App = {
Expand Down Expand Up @@ -140,18 +135,26 @@ let app =
(~inject, ~schedule_event) =>
apply(~schedule_action=x => schedule_event(inject(x))),
~default_model=Model.load(Model.blank),
~reset=on_startup,
);

open Bonsai.Let_syntax;

let view = {
let startup_completed = Bonsai.toggle'(~default_model=false);
let%sub startup_completed = startup_completed;
let%sub app = app;
let%sub after_display = {
switch%sub (startup_completed) {
| {state: false, set_state, _} =>
let%arr (model, inject) = app
and set_state = set_state;
Bonsai.Effect.Many([on_startup(~inject, model), set_state(true)]);
| {state: true, _} => Bonsai.Computation.return(Ui_effect.Ignore)
};
};
let%sub () = Bonsai.Edge.lifecycle(~after_display, ());
let%arr (model, inject) = app;
Haz3lweb.Page.view(~inject, model);
// Bonsai.Computation.map(app, ~f=((model, inject)) =>
// Haz3lweb.Page.view(~inject, model)
// );
};

switch (JsUtil.Fragment.get_current()) {
Expand Down

0 comments on commit 2e2aa4c

Please sign in to comment.