Bartosz Szewczyk
Html + CSS
Redux?
reFrame?
type alias Model a =
{ id : Int
, values : List (Int, a)
, previous : a
, child : List (Int, a)
}
type Action a
= Create a
| Update (Int, a)
| InsertMany List (Int, a)
update : Action a -> Model a -> Model a
update action model =
case action of
Create newVal ->
{ model | values = model.values ++ [(model.id, newVal)]
, id = model.id + 1 }
Update (id, newVal) ->
{ model | values =
List.map (update id newVal) model.values }
InsertMany newValues ->
{ model | values = model.values ++ newValues }
type Maybe a = Just a | Nothing
doSomethingWithA : Maybe Int -> Int
doSomethingWithA a =
case a of
Just i ->
someAProcessing i
Nothing ->
someDefaultInt
hermann =
{ first = "Hermann"
, last = "hesse"
}
isOver 50 person =
person.age > 50
answer =
isOver50 hermann
view: Signal.Address Action -> Model -> Html
view address model =
div []
[ button [ onClick address Decrement ]
[ text "-" ]
, div []
[ text (toString model) ]
, button [ onClick address Increment ]
[ text "+" ]
]
arguments
return
hidden inputs
side-effects
bacon.js
kefir.js
Mouse.position : Signal (Int, Int)
Keyboard.presses : Signal Int
filter : (a -> Bool) -> a -> Signal a -> Signal a
onlyNumbers : Signal Int
onlyNumbers = Signal.filter
(\keyCode -> keyCode >= 48 && keyCode <= 57)
48 presses
map : (a -> result) -> Signal a -> Signal result
numbersPressed : Signal Int
numbersPressed =
Signal.map (\keyCode -> keyCode - 48) onlyNumbers
foldp : (a -> state -> state) -> state -> Signal a -> Signal state
sumPressed : Signal Int
sumPressed =
Signal.foldp (\n res -> res + n) 0 numbersPressed
SuperComponentC.elm
SubComponentA.elm
SubComponentB.elm
C
B
A
view
model
update
view
model
update
// embed our Elm program in <div>
var app = Elm.embed(Elm.Stamper,
document.getElementById('#stamper');
// fullscreen version of Stamper
var app = Elm.fullscreen(Elm.Stamper);
// Stamper with no graphics
var app = Elm.worker(Elm.Stamper);
port addUser : Signal (String, UserRecord)
app.ports.user.send([
"Tom",
{ age: 32, job: "lumberjack" }
]);
app.ports.user.send([
"Sue",
{ age: 37, job: "accountant" }
]);
port requestUser : Signal String
port requestUser =
signalOfUsersWeWantMoreInfoOn
app.ports.requestUser.subscribe(databaseLookup);
function databaseLookup(user) {
var userInfo = database.lookup(user);
app.ports.user.send(user, userInfo);
}
Scalable maintainable architecture
André Medeiros