alexmingoia / purescript-pux

Build type-safe web apps with PureScript.
https://www.purescript-pux.org
Other
566 stars 76 forks source link

bidirectional route parsing #120

Open bigs opened 7 years ago

bigs commented 7 years ago

hey!

been looking into using pux for a project with a client and am generally feeling good about it! i was wondering if you'd be interested in me putting together a PR implementing bidirectional parsing for the routing layer, i.e. extending the api to create parser/generators that can be interpreted to parse a string into an ADT or, using the same construction, render an ADT into a string representing the route.

this should eliminate the need for functions like this one in the todomvc demo and would give me a nice opportunity to get more intimate with pux.

cool project! cole

alexmingoia commented 7 years ago

Yeah that'd be great to have.

1) Does it need to be part of Pux, and can the router be separated as another library? Data.Route or something. I think what's in Pux now could probably live as another module. 2) There's a lot of ways to serialize and parse routes. Maybe you could provide a pseudo-code example of what you're thinking?

bigs commented 7 years ago

ah, good thoughts. i think an external lib would be fine :) i've tinkered with plenty of haskell impls in the past, so i'll take a peek at those, reflect on purescript's differences (this weekend?) and update the issue here.

paluh commented 7 years ago

@bigs You can check my port of boomerang library. Recently I've added API based on new generics:

https://github.com/paluh/purescript-boomerang/blob/master/src/Text/Boomerang/Generic.purs

here is a simple usage example:

https://github.com/paluh/purescript-boomerang/blob/master/test/Text/Boomerang/String.purs#L66

Additionally there is a project which is based on old generics and generates bidirectional routes fully automatically. I want to extend its API and add Options to routes builders. I think about something similar to Options from purescript-argonaut-generic-codecs:

https://github.com/paluh/purescript-routing-bob

I have also purescript-puxing-bob which was an experimentation field for best integration of these libraries into old pux. You should igore it, because now when smodler is used and we have proper monad instance I think that it should be easier to add state layer with router to rendering flow (I don't have time to experiment on this now).

Unfortunately both libraries are not ported to purescript-0.11 yet. Let me know what do you think. I'm really open to propositions and discussion.

bigs commented 7 years ago

@paluh lovely! going to dig into these this afternoon. not finding a ton of resources on it and i'm fairly new to PS (tho quite experienced w/ haskell & ML)—what are the breaking changes in 0.11?

bigs commented 7 years ago

an update—things picked up quite a bit with the client so i'm only now getting to frontend work. this is still something i'm interesting in pursuing! i think it will probably rely on generics. i'll keep you posted if i make any forward progress.

bigs commented 7 years ago

bumping this! i've since embarked on a rather extensive project and found that Data.Codec is a perfect fit for this. my approach will probably be extending purescript-routing to accept codecs. i'm personally using halogen on my project but it should benefit pux as well!