alexmingoia / purescript-pux

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

Make (!) operator work without needing (#) #21

Closed nullobject closed 8 years ago

nullobject commented 8 years ago

I love the shorthand syntax for specifying HTML elements. However, some elements don't have children, for example:

img ! href "foo.jpg"

Unfortunately this doesn't work 😭

alexmingoia commented 8 years ago

You would need to write img ! href "foo.jpg" ## [].

It's just much simpler and straightforward to use array notation instead of the overloaded do, and I'm planning on rewriting the examples and docs to encourage that.

For ! to work without children, Html would have to be monadic. There would also need to be separate constructors, one that takes arrays and one that takes a single argument for use with do notation. One way to do this is to provide two modules that export element constructors, one for array notation and the other do notation. My only hangup is what the modules would be called. Maybe Pux.Html.Elements for vanilla array constructors and Pux.Html.Elements.Simple or Pux.Html.Elements.Do for the monadic versions. Both constructors would result in the same type, so there would be no issue mixing and matching views that were written in either style. The downside is that would be a breaking change.

eskimor commented 8 years ago

Plus 1 for array notation - I found it ugly when I first saw it in Elm, but you get used to it pretty quickly. It is simple and consistent and also easy to write and understand.

alexmingoia commented 8 years ago

Examples and docs have been updated to use array notation. I'm closing this for now (just reopen if you have something else to say). If there are solid proposals for how to provide a monadic DSL that is built ontop of the array-notation DSL, then the discussion should be continued there.

nullobject commented 8 years ago

Cool, thanks for the feedback 👍