Logica
Logica is an optimised state model that uses the observer pattern. Node
and Dependent
can be bound to Recreate nodes as they provide an
__RCImplementor
.
Node
A Node
represents an entry point for a value, when updated, it relays changes
down the tree to Dependents
local Text = Logica.Node("ez")
print(Text:get()) --> ez
Dependent
A Dependent
is a listener that reacts to the changes of other Dependents
or
Nodes
, then creates a new output from those objects
local coolNumber = Logica.Node(2)
local evenCoolerNumber = Logica.Dependent(function()
return coolNumber:get() * 2
end)
coolNumber:set(4)
warning
Dependents should not yield, the state engine assumes all nodes in the tree resume within the same resumption cycle.
Observer
Observers represent the exit of a computation, and cannot be depended upon, but
still react to other Nodes
changing around it
local coolNumber = Logica.Node(2)
local evenCoolerNumber = Logica.Dependent(function()
return coolNumber:get() * 2
end)
Logica.Observer = Logica.Observer(function()
print(`the number is {evenCoolerNumber:get()}`)
end)
coolNumber:set(4)
Observer updates are deffered to the next tick, and do not implement
__RCImplementor
unlike other Nodes in Logica.