autoscale: true text: Lato Bold header: Lato Black code: Iosevka
or, how I learned to stop worrying and love ports
- Work: Day One
- Twitter: @splodingsocks
- Github: @splodingsocks
[.footer: Photo by Dariusz Sankowski on Unsplash]
[.build-lists: true]
- Client-side database
- Hand-written native code to wrap DB
- Runtime errors 😭
- No compiler help
- Mentioned in Slack bad experience with native code
- Mentioned that using ports would be even worse
- Evan replied
- I had been using an incorrect mental model of ports
- I revised my brain and re-architected
- No more native code
- 💸💰🤑💸💰🤑💸💰🤑
- Elm & JS remain separate worlds with separate concerns
- Scaling JS-Elm interaction is simple (a simple pattern is simple to follow)
[.footer: Story time]
Our data is stored in IndexedDB, and we need to create, modify, and delete records (for starters)
[They're] like JavaScript-as-a-Service -- guide.elm-lang.org
port updateEntryContents : Entry -> Cmd msg
port updatedEntryContents : (Entry -> msg) -> Sub msg
port createEntry : () -> Cmd msg
port entryCreated : (Entry -> msg) -> Sub msg
port deleteEntry : Int -> Cmd msg
port entryDeleted : (Int -> msg) -> Sub msg
- Ports make JavaScript == Service
- BUT
- Service
/=
server - Ports
/=
HTTP + Promises
- Service
- BUT
The interaction between Elm & JS is modeled on a mature design pattern called The Actor Model
TODO: Insert table of languages that use the actor model and their years of inception
TODO: Cite the Elm Town episode
TODO: Make the example of text messages vs phone calls
Show meaningful snippets from InfoForOutside
and InfoForElm
TODO: Diagram of Day One after Web Workers
^ The API for Web Workers follows a pattern like the Actor Model. No re-architecting and almost zero work was required to connect the JS back up with Elm after moving all of the JS code into a Web worker. Instead of two actors passing messages, we now had three. That's all.
^ Demo the Day One Web app in full glory syncing multiple journals with hundreds of entries while still seamlessly navigating around the UI. Show off the async image loading as well.
- Contact info
- Sample code
- Elm Town