Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support routing messages as custom events #7

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion minttea/event.ml
@@ -1,9 +1,10 @@
open Riot

type t = KeyDown of string | Timer of unit Ref.t | Frame
type t = KeyDown of string | Timer of unit Ref.t | Frame | Custom of Message.t

let pp fmt t =
match t with
| KeyDown key -> Format.fprintf fmt "KeyDown(%s)" key
| Timer ref -> Format.fprintf fmt "Timer(%a)" Ref.pp ref
| Frame -> Format.fprintf fmt "Frame"
| Custom _msg -> Format.fprintf fmt "Custom"
6 changes: 5 additions & 1 deletion minttea/minttea.mli
@@ -1,7 +1,11 @@
open Riot

module Event : sig
type t = KeyDown of string | Timer of unit Ref.t | Frame
type t =
| KeyDown of string
| Timer of unit Ref.t
| Frame
| Custom of Message.t

val pp : Format.formatter -> t -> unit
end
Expand Down
11 changes: 7 additions & 4 deletions minttea/program.ml
Expand Up @@ -8,10 +8,13 @@ let make ~app ~fps = { app; fps }
exception Exit

let rec loop renderer (app : 'model App.t) (model : 'model) =
match receive () with
| Timer ref -> handle_input renderer app model (Event.Timer ref)
| Io_loop.Input event -> handle_input renderer app model event
| _ -> loop renderer app model
let event =
match receive () with
| Timer ref -> Event.Timer ref
| Io_loop.Input event -> event
| message -> Event.Custom message
in
handle_input renderer app model event

and handle_input renderer app model event =
let model, cmd = app.update event model in
Expand Down