Hop has changed in many ways in version 3. Please review the Getting started guide. Following is an overview of the major changes.
Now routes can take values, instead of:
type Route
= Home
| Users
| User
| Token
You can have values attached:
type Route
= Home
| Users
| User Int
| Token String
Routes are now defined using matchers. So instead of
routes =
[ ("/users/:int", User) ]
You do:
import Hop.Matchers exposing(match2)
userMatcher =
match2 User "/users/" int
matchers =
[userMatcher]
This is so we can have stronger types e.g. User Int
.
Hop.signal now returns a tuple with (Route, Location)
. Your application needs to map this to an action. e.g.
type Action
= HopAction ()
| ApplyRoute ( Route, Location )
taggedRouterSignal : Signal Action
taggedRouterSignal =
Signal.map ApplyRoute router.signal
This is so routes (Route
) are different type than the application actions.
Before Hop returned a payload
with a dictionary with matched parameters.
Now it returns the matched route with the values e.g. User 1
and a Location
record in the form of a tuple:
(User 1, location)
location
has the information about the current path and the query:
{
path = ["users", "1"],
query = <Dict String String>
}
In your views you don't need to 'search' for the correct parameter in the payload anymore. The parameters are now in the route e.g. User 1
.
So instead of doing:
userId =
model.routerPayload.params
|> Dict.get "userId"
|> Maybe.withDefault ""
You simply get the id from the route:
case User userId ->
...
The query is still a dictionary. The query is now in the location
record as shown above.