Dependent type since v0.2 ¶
A graph object which can receive updates from dependecies on the reactive graph.
Most often used with state objects, though the reactive graph does not require objects to store state.
{
dependencySet: Set<Dependency>,
update: (self) -> boolean
}
Fields¶
dependencySet
- stores the graph objects which this object can receive updates from
Methods¶
since v0.2
Dependent:update()¶
Called when this object receives an update from one or more dependencies.
If this object is a dependency, and updates should be propagated to further dependencies, this method should return true. Otherwise, to block further updates from occuring (for example, because this object did not change value), this method should return false.
() -> boolean
Example Usage¶
-- these are examples of objects which are dependents
local computed: Dependent = Computed(function()
return "foo"
end)
local observer: Dependent = Observer(computed)
Automatic Dependency Manager¶
Fusion includes an automatic dependency manager which can detect when graph objects are used in certain contexts and automatically form reactive graphs.
If a dependent wants to automatically capture uses of dependencies inside of
certain contexts (for example, a processor callback) then the
captureDependencies()
function may be invoked, with the callback and the
object's dependency set as arguments.
This will detect all useDependency()
calls from inside the callback, and save
any passed dependencies into the set.