halfzebra/elm-examples

Improve key-combinators example

Closed this issue · 1 comments

welf commented
  1. When you press Tab key, the focus goes to the address bar of browser and the KeyCode of this key remains in the model, because Elm app doesn't get the event Keyboard.ups. It is better to clear the model explicitly on Keyboard.ups (at least the model will be cleared on the next Keyboard.ups event).
  2. It is better to use :: operator instead of ++.
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
    case msg of
        KeyDowns code ->
            ( if code `List.member` model then
                model
              else
                code :: model
            , Cmd.none
            )

        KeyUps code ->
            ( [], Cmd.none )

@welf thank you for your contribution! I have improved the example in #5

I haven't solved the problem with Tab, the only reasonable way is to clear up the list of pressed buttons right away, but then it would make sense to handle other combinations, which will make browser window to loose focus.

I'm not sure if this would be an appropriate place for a comprehensive example.

You are very welcome to hit me with a PR, if you have good ideas on that.

For now I will close this issue.