Improve docs

This commit is contained in:
Aaron Smith 2023-08-22 16:46:38 +01:00
parent 6764d34ce1
commit fdc72a17f0
5 changed files with 33 additions and 30 deletions

View file

@ -25,10 +25,13 @@ count(count() + 1) -- increment source by 1
Below is an example of a stateful counter component.
```lua
local function Counter()
local function Counter(props: { Position: UDim2 })
local count = source(0)
return create "TextButton" {
Position = props.Position,
Size = UDim2.new(200, 50),
Text = count,
Activated = function()
@ -38,21 +41,22 @@ local function Counter()
end
```
Each call of `Counter {}` will create a new counter element, each with their own
independent count.
Vide detects when you assign a function to a property. This is known
as *binding* and doing so will cause the property to *automatically* update
whenever a source in that function is updated, by rerunning the function and
assigning its return value. You can only bind non-event
properties, otherwise the function is connected as the event callback.
You as the programmer do not have to worry about manually updating variables or
UI instances, you can just focus on defining how the data maps to UI and
everything will update when changes occur.
This allows you as the programmer to not need to manually update GUI as the state
of your program changes. You just define how the data maps to UI, and Vide's
reactive system will surgically update any properties depending on sources that
are changed.
Each call of `Counter {}` will create a new counter element, each with their own
independent count.
Since sources are just functions, you can pass an external source to a component
like so:
Since sources are just functions, you can also pass external sources to
components like so:
```lua
local function Text(p: {