eager-tiger-27508
10/23/2021, 3:29 PMlucid. https://chrisdone.com/posts/lucid2/ has examples of what lucid looks like if you're interested. Interestingly, HTML is a monad!!eager-tiger-27508
10/23/2021, 3:33 PMincalculable-pager-33872
10/23/2021, 3:53 PMmysterious-toddler-20573
10/23/2021, 3:57 PMmysterious-toddler-20573
10/23/2021, 3:58 PMmysterious-toddler-20573
10/23/2021, 3:58 PMmysterious-toddler-20573
10/23/2021, 3:58 PMeager-tiger-27508
10/23/2021, 3:59 PMincalculable-pager-33872
10/23/2021, 4:03 PMeager-tiger-27508
10/23/2021, 4:04 PMgorgeous-airport-54386
10/23/2021, 4:04 PMgorgeous-airport-54386
10/23/2021, 4:04 PMeager-tiger-27508
10/23/2021, 4:06 PMgorgeous-airport-54386
10/23/2021, 4:08 PMmysterious-toddler-20573
10/23/2021, 4:12 PMmost-jelly-15242
10/23/2021, 4:15 PMx-data within the partials that are updated through htmx, you lose the x-data state prior to the update. If you use morphdom, the state is preserved. There are ways around this if you manage the state yourself server side and keep the x-data variables updated, or if you use the new Alpine $persist plugin. Also you can completely ignore this if you avoid having components within htmx partials.incalculable-pager-33872
10/23/2021, 4:46 PMeager-tiger-27508
10/23/2021, 5:08 PMgorgeous-ghost-95789
10/23/2021, 5:29 PM/htmx/src/htmx.d.ts. Is there something like this in PureScript? Something that would make it nicer to use in a Haskell environment without porting the whole library out of Javascript?eager-tiger-27508
10/23/2021, 6:34 PMhx-get, hx-post, etc. actually exist. These are things that Haskell developers will enjoy. For example, let's say I had:
html
<button hx-get="html/contacts">
Click Me!
</button>
In the Haskell HTML templating language called lucid this would be:
haskell
buttonSnippet :: Html () -- This type annotation is optional
buttonSnippet = button_ [hx_get_ "html/contacts"] "Click Me!"eager-tiger-27508
10/23/2021, 6:34 PMhx_get_ , hx_post_, hx_include_ so you can use HTMX in lucid templates. They all have the type Text -> Attribute. They are functions that take a string and return an Attribute value.
These aren't safe though since I could put some string there that wouldn't make sense. For example:
haskell
buttonSnippetFail :: Html ()
buttonSnippetFail = button_ [hx_get_ "html/thisEndpointDNE%#2"] "Click Me!"
This would still "work" and I could deploy it and everything, but the end product wouldn't make sense. Clicking the button would do nothing since the endpoint doesn't exist. This a bug that can be caught by the compiler since we humans miss things all the time.
In Haskell, we try to get rid of programs that don't make sense by using type specifications. The compiler doesn't build programs that don't make sense, because even if they are built, deployed, and run, they won't work properly. Might as well be upfront about it, right?
The higher-level HTMX library I'm working on does just this. To do this, I'm combining lucid with a well-know Haskell library for specifying APIs as types called servant. So using servant we can define our HTML contacts endpoint as a type:
haskell
type Contacts = "html" :> "contacts" :> Get '[HTML] [Contact]
-- The following basically brings the Contacts type to the value level
contactsEndpoint :: Proxy Contacts
contactsEndpoint = Proxyeager-tiger-27508
10/23/2021, 6:34 PMhx_get_safe_, hx_post_safe_, etc. We can use these like so to create a type-safe version of our button example:
haskell
type Contacts = "html" :> "contacts" :> Get '[HTML] [Contact]
contactsEndpoint :: Proxy Contacts
contactsEndpoint = Proxy
buttonSnippet :: Html ()
buttonSnippet = button_ [hx_get_safe_ contactsEndpoint] "Click Me!"
By using the type-safe variants, the compiler prevents me from deploying any code that would make a call to an endpoint that doesn't even exist in my backend. If the code compiles, it's guaranteed to work.
In a small example this obviously isn't much help, but in medium-to-large apps this is great and has many benefits in my opinion. Especially long-term for maintainability and refactorablity.late-king-98305
10/24/2021, 2:57 AMhtmx.process, but flipping my thinking got the logic back on the server, making the browser a request-and-render engine instead of setting values, making calls, etc.big-airline-13935
10/24/2021, 11:03 AMtall-cat-32859
10/24/2021, 11:06 AMproud-dentist-32878
10/24/2021, 11:56 AMmysterious-toddler-20573
10/24/2021, 2:36 PM