SPAs, Without the SPA
Ian Duggan
The Rails Way?
Friction Frustrates Me
• Controllers
• Views
• Models
• Templates
• <%= ERB %>
Just Give Me Functions
A Compendium of
Terrible Ideas
(maybe?)
Scratch That Itch
Let's Be Grandiose
Uncle Bob
Screaming Architecture
Ports and Adatpers
Has Rails Ruined a
Generation of Programmers?
• Keep it simple
• Be suspicious of frameworks
• Take only what you need
Phoenix File Layout
Feature Folders
It Works…
ERB Templates
Taggart
(HTML as Code)
Design Goals
• Simple Elixir-based generation of tag-based
markup
• Interoperate properly with Phoenix helpers
Basic Syntax
Basic Syntax
Nesting
Phoenix Compatibility
Phoenix Helpers
Phoenix Views
Phoenix Views
Benchmarks
Benchmarks
https://github.com/ijcd/taggart
Now I Need Widgets
DOM-Aware
"UIkit is listening for DOM manipulations
and will automatically initialize, connect and
disconnect components as they are inserted
or removed from the DOM. That way it can
easily be used with JavaScript frameworks
like Vue.js and React."
Lots of Cool Widgets
Lots of Cool Widgets
Lots of Cool Widgets
Lots of Cool Widgets
Lots of Cool Widgets
Complicated Markup
It Can Be Easier
And Fun
https://github.com/ijcd/uikit_ex
https://github.com/ijcd/uikit_demo
Javascript Stuff
• jQuery
• Ember
• Angular
• React/Redux
• Om/Clojurescript
Drab
https://github.com/grych/drab
This looks promising…
No taggart allowed…
Unpoly
https://github.com/unpoly/unpoly
Replaces Fragments
Decorators
But I Want Something More
• The feel and Reactivity of React
• The simplicity of Elm’s model/update/view
• Completely in Elixir (minimal javascript)
GenServer?
Presto
• GenServer-based components
• Channel-based communication
• Unpoly-based DOM updates
Simple Loop
GenServer Browser
UI Updates
DOM Events
Update State
DynamicSupervisor
• PrestoSupervisor manages components
• Components are scoped to a visitor_id, unique
to each browser
• On-page components are further scoped with
named identifiers
Setup Javascript Client
Wire Up A Channel
Call into a Component
Component Init
Component Update
Component Render
Performance
• www.prestochange.io
• eu.prestochange.io
Electron
You Need A Hack for Brunch…
package.json
brunch-config.js
Testing?
• Split render() with helpers
• Split update() with into helpers
Growing Your App?
(it’s all just functions…)
In Development
• Push-messages from the server
• TodoMVC Example
• Lenses and Optics for embedded components
• Time-traveling Debugger
(I did say there were still problems to be solved…)
https://github.com/ijcd/presto
https://github.com/ijcd/presto_demo
https://github.com/ijcd/prestochange

ElixirConfEU 2018 - SPAs Without the SPA