Reactive programming
type Border =
inherit Control
var obs left : u32 = 0
var obs right : u32 = 0
var obs up : u32 = 0
var obs down : u32 = 0
var obs content : Option<Control> = None
The obs
modifier creates a container of type mut Atom<T>
that can send notifications when a value changes.
let content_width = content@atom.map { case _ of
None -> 0
Some control -> control.width }
content@atom
returns a container, map
is a method defined for the Atom<T>
.
let thickness = (border.left@atom
border.right@atom
border.up@atom
border.down@atom)
|> to_atom
Tuple of atoms can be transformed into an atom of tuples, the type of thickness
is Atom<(u32, u32, u32, u32)>
.
val memory@atom = (content_width, content_height, thickness)
|> to_atom
|> map { width, height, thickness ->
if width == 0 || height == 0
then None
else Some (width, height, thickness) }
|> option_map { width, height, (left, right, up, down) ->
...
MeshMemory.from_quads quads.as_slice }
Because of the @atom
modifier, binding memory
has a type Option<MeshMemory>
and not Atom<Option<MeshMemory>>
.
let obs size : u32 = 10
let obs factor : f32 = 0.8
margin.up@obs = size@obs as f32 * factor@obs |> as<u32>
Field up
of the margin
will be updated every time size
or factor
changes.