-
Covers the following things:
- Having multiple sub pages with their own model/view/update functions. More specifically, the difficulty I had in adding these sub pages to one overarching Main view, thanks to the mismatched types. It was difficult for me to understand how to make a sub pages update signature of
SubMsg -> SubModel -> (SubModel, Cmd SubMsg)work in the Main update function.- Yes, I could easily get the submodel out of the update command by using
SubPage.update mainModel.subPageModeland pulling it out with a case expression, but I couldn’t figure out what to do with theCmd SubMsgpart; do I just discard it? what if the sub page is doing an http operation, which that Cmd holds? It would never update if I just discard it. - Answer was to use
Cmd.map, just like you useHtml.map.
- Yes, I could easily get the submodel out of the update command by using
- If you’re doing a SPA, you probably want to use
Browser.applicationto start your program. This wants your view function to return aBrowser.Document msg, which is just a type alias for a record that looks like{ title : String, body : Html list }.- Difficulty mapping the sub views — I couldn’t do
Html.map (subview)because the subview was returning aBrowser.Document. The solution was to map every item inBrowser.Document.bodywithHtml.map.
- Difficulty mapping the sub views — I couldn’t do
- Another difficulty in one of the subviews that has a concept of multiple pages that are not different URLs. Think the steps of a checkout, where first you enter a billing address, then shipping address, then payment information. I had trouble passing a function to each of those steps that would bubble up an event to the view and tell it to switch to the next step.
- Having multiple sub pages with their own model/view/update functions. More specifically, the difficulty I had in adding these sub pages to one overarching Main view, thanks to the mismatched types. It was difficult for me to understand how to make a sub pages update signature of
-
Sidenote, I really wish Elm’s type signatures made generics a little more obvious. It’s cognitively more work for me to visually parse the difference between
Browser.Document msgandBrowser.Document Msg. It would be easier if Elm used some kind of symbol or annotation to indicate thatmsgis generic; something likeBrowser.Document<msg>like C#, orBrowser.Document 'msglike F#.
Learn how to build rock solid Shopify apps with C# and ASP.NET!
Did you enjoy this article? I wrote a premium course for C# and ASP.NET developers, and it's all about building rock-solid Shopify apps from day one.
Enter your email here and I'll send you a free sample from The Shopify Development Handbook. It'll help you get started with integrating your users' Shopify stores and charging them with the Shopify billing API.