eeue56 / elm-html-test

Test elm-html in Elm!
http://package.elm-lang.org/packages/eeue56/elm-html-test/latest
BSD 3-Clause "New" or "Revised" License
67 stars 15 forks source link

Event API Revisions #27

Closed rtfeldman closed 7 years ago

rtfeldman commented 7 years ago

Having spent some time with @rogeriochaves's awesome event triggering system, I have some ideas for how to revise the API:

Current API

test "input produces expected Msg" <|
    \() ->
        Html.input [ onInput Change ] [ ]
            |> Query.fromHtml
            |> Events.simulate (Input "cats")
            |> Events.expectEvent (Change "cats")

Proposed Change

test "input produces expected Msg" <|
    \() ->
        Html.input [ onInput Change ] [ ]
            |> Query.fromHtml
            |> Event.simulate (Event.input "cats")
            |> Event.expect (Change "cats")

The big change is making (lowercase) functions rather than (uppercase) union type constructors for the events.

Before:

|> Events.simulate (Input "cats")
|> Events.expectEvent (Change "cats")

After:

|> Event.simulate (Event.input "cats")
|> Event.expect (Change "cats")

This has a few benefits.

  1. It's easier to tell at a glance which is the Msg (the uppercase Change) and which is the event (the lowercase input "cats" - as opposed to the previous Input "cats").
  2. Each event helper can have its own documentation, which is especially helpful in the case of nontrivial ones like check.
  3. Adding new helpers can be a minor version bump.

Other changes include:

Thoughts?

rogeriochaves commented 7 years ago

Cool! It crossed my mind using functions instead of union types for the events, but I haven't thought deeper on the advantages or disadvantages of it. You won me at "Each event helper can have its own documentation".

LGTM

eeue56 commented 7 years ago

woa, hold up,I wanna review first

eeue56 commented 7 years ago

I've putsuggested changes on #29 @rtfeldman

rtfeldman commented 7 years ago

Sorry @eeue56! Didn't realize you wanted to weigh in first. 😅