seanhess / hyperbole

Haskell interactive serverside web framework inspired by HTMX
Other
87 stars 6 forks source link

Feature Request: Supporting better scenario to keep current browser's URL updated #29

Open benjaminweb opened 4 weeks ago

benjaminweb commented 4 weeks ago
seanhess commented 4 weeks ago

Agreed, this is needed for sure.

benjaminweb commented 4 weeks ago

Which steps are required to make it happen?

seanhess commented 4 weeks ago
  1. Design the interface - how does the user control this? (This is the hard part)
  2. Add a metadata option to the communication protocol that allows the server to set window.history. Something like |HISTORY|/whatever?hello=true
  3. Implement it client-side.
benjaminweb commented 4 weeks ago

Would that be just another event the user has to call?

seanhess commented 4 weeks ago

Hmm... I'm not sure I love that logic being in the view function. Would it be better in the handler somehow?

benjaminweb commented 4 weeks ago

You surely know the architecture of Hyperbole better than me :). So what do we have? An action to update the location in the browser, right? And we'd need something to just take care of that. That sounds to me like just another handler, right or wrong?

seanhess commented 4 weeks ago

My question is a design consideration rather than an architectural one. Is updating the browser's url / history more of a "view" thing, or more of an "effect" thing?

If it were in a handler, it could be added to the Hyperbole effect easily.

myHandler _ DoSomething = do
  ...
  -- this would set the whole thing
  setUrl "/users?filter=active"
  -- this would set only the query, and keep the current route
  setQueryParams [("param", "woot")]
  pure myView

This would result in an extra instruction being sent to the client. We would want to make generating the URL more ergonomic. Probably related to #32 . We need a way to generate URLs from a Route + Query Params.