bullet.lua
function draw_list(x, y)
return {
{'setLineWidth',
Consts.bullet.width},
{'line', x, y,
x, y + Consts.bullet.height},
{'setLineWidth', 1},
}
end
invader.lua
function bounced(x)
return x <= 0 or
(x + Consts.invader.side) >=
Consts.screen.width
end
return {
_draw_list=L(draw_list)(_x, _y),
_bounced=L(bounced)(_x),
}
swarm.lua
function bounce()
_v = _v() * -1
_y = _y() + Consts.invader.close
end
link(cond(_bounced), bounce)
Slide 45
Slide 45 text
Demo
Slide 46
Slide 46 text
• Imperative exception to Functional graph
traversal
• Acts like a fork
• “Reacts” to other Reactors
• All reactive variables are Reactors
The Reactor
Slide 47
Slide 47 text
git checkout -f PLAYER
Slide 48
Slide 48 text
world.lua
player = Player(Consts.player.initial.x,
Consts.player.initial.y)
Slide 49
Slide 49 text
player.lua
function constructor(ix, iy) ...
_x = ix
_y = iy
return {
_draw_list = L(draw_list)(_x, _y),
}
Slide 50
Slide 50 text
player.lua
function draw_list(x, y)
return {{
'triangle', 'line',
x, y,
x + Consts.player.width,
y + Consts.player.height,
x - Consts.player.width,
y + Consts.player.height,
}}
end
player.lua
return {
_draw_list = L(draw_list)(_x, _y),
left = move(-1),
right = move(1),
}
Slide 55
Slide 55 text
player.lua
function move(d)
return function()
_dir = d
end
end
Slide 56
Slide 56 text
player.lua
_dir = 0
_x = ix
_y = iy
_v = L(v)(_dir, delay(_x))
_x = ix + S(_v)
Slide 57
Slide 57 text
Delayed Evaluation
_dir v
_v
_x
_int_v
Slide 58
Slide 58 text
Delayed Evaluation
_dir v
_v
_x
_int_v
Slide 59
Slide 59 text
player.lua
function v(dir, x)
if x then
...
else
return 0
end
end
Slide 60
Slide 60 text
player.lua
if x then
if (x <= C.player.width
and dir < 0) or
(x >= C.screen.width - C.player.width
and dir > 0) then
return 0
else
return Consts.player.speed * dir
end
end
invader.lua
function box(x, y)
return {x=x, y=y,
width=Consts.invader.side,
height=Consts.invader.side}
end
Slide 72
Slide 72 text
invader.lua
function colliding(abox, bbox)
ax2, ay2 = abox.x + abox.width,
abox.y + abox.height
bx2, by2 = bbox.x + bbox.width,
bbox.y + bbox.height
return abox.x < bx2 and ax2 > bbox.x and
abox.y < by2 and ay2 > bbox.y
end
Slide 73
Slide 73 text
invader.lua
function die()
_alive = false
end
link(cond(_hit), die)
Slide 74
Slide 74 text
invader.lua
function draw_list(alive, x, y)
if alive then ... else
return {}
end
function bounced(alive, x)
if alive then ... else
return false
end
Slide 75
Slide 75 text
No content
Slide 76
Slide 76 text
Reactivity
Huh! Good God!
What is it good for?
Slide 77
Slide 77 text
No content
Slide 78
Slide 78 text
No content
Slide 79
Slide 79 text
•Model - View - Controller
•Browser ⁶ Server
•Workflows
Slide 80
Slide 80 text
Workflow?!
complete := seen [
submission
review
confirmation
]
Slide 81
Slide 81 text
Event Sourcing
Martin Fowler’s
Slide 82
Slide 82 text
most productivity apps
editors
not useful?
relational databases
backup/restore
filesystems (snapshot)
git
Redo
Undo
Event Based
Event Based State Based
State Based