Concepts Summary
A summary of all the concepts covered during the crash course.
Source
A source of data.
Stores a single value that can be updated.
Created with source().
Derived Source
A new source composed of other sources.
Created with a plain function or with derive().
Effect
Anything that happens in response to a source update.
Created with effect().
Stable Scope
One of the two types of Vide scopes.
Created by:
root()untrack()show()indexes()
Stable scopes do not track sources and never rerun.
New stable or reactive scopes can be created within a stable scope.
Reactive Scope
Created by:
effect()derive()
Reactive scopes do track sources and will rerun when those sources update.
Reactive scopes cannot be created within a reactive scope, but stable scopes can be created within a reactive scope.
Scope Cleanup
When a scope is rerun or destroyed, all scopes created within it are automatically destroyed.
Any functions queued by cleanup() are also ran.
Reactive Graph
The combination of stable and reactive scopes can viewed graphically, called a reactive graph. This can be a more intuitive way to think of the relationships between effects and the sources they depend on.
Code
local count = source(0)
root(function()
local text = derive(function()
return "count: " .. count()
end)
effect(function()
print(text())
end)
end)Graph resulting from code
Notes:
- Since
countis a source, not an effect, it can exist outside of scopes. - An update to
countwill causetextto rerun, which then causeseffectto rerun. - When the root scope is destroyed,
textandeffectwill be destroyed alongside it, since they were created within it.countwill be untouched and future updates tocountwill have no effect.