Skip to content

Commit

Permalink
Kosher way to communicate via subscriptions
Browse files Browse the repository at this point in the history
This way we order Elm runtime to handle the message.
  • Loading branch information
fidel committed Apr 4, 2024
1 parent e2bdbe6 commit 76b8c18
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 11 additions & 1 deletion ruby_event_store-browser/elm/src/Layout.elm
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Msg
| OnSelect Search.Stream
| OnQueryChanged Search.Stream
| RequestSearch
| CloseSearch
| ToggleBookmark String


Expand All @@ -52,12 +53,18 @@ port toggleDialog : String -> Cmd msg
port requestSearch : (() -> msg) -> Sub msg


port closeSearch : (() -> msg) -> Sub msg


port toggleBookmark : String -> Cmd msg


subscriptions : Sub Msg
subscriptions =
requestSearch (always RequestSearch)
Sub.batch
[ requestSearch (always RequestSearch)
, closeSearch (always CloseSearch)
]


buildModel : Model
Expand Down Expand Up @@ -143,6 +150,9 @@ update msg model =
RequestSearch ->
( model, toggleDialog searchModalId )

CloseSearch ->
( model, toggleDialog searchModalId )

ToggleBookmarksMenu ->
( { model | internal = Model model.internal.search (not model.internal.displayBookmarksMenu) model.internal.bookmarks }, Cmd.none )

Expand Down
3 changes: 1 addition & 2 deletions ruby_event_store-browser/public/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ window.addEventListener("keydown", function (event) {
}

if (event.key === "Escape") {
const dialog = document.querySelector(`#${id}`);
dialog.open ? dialog.close() : null;
app.ports.closeSearch.send(null);
event.preventDefault();
}
});
Expand Down

0 comments on commit 76b8c18

Please sign in to comment.