This commit is contained in:
Alice 2024-12-29 21:38:00 +01:00
commit 63077355eb
66 changed files with 1741 additions and 1671 deletions

View file

@ -3,7 +3,13 @@
Explicitly creating effects to update properties is tedious. You can
*implicitly* create an effect to update properties instead.
<<<<<<< HEAD
```luau
=======
::: code-group
```luau [Implicit Effect]
>>>>>>> 58a31a1b329e922dc86c554e8220012ab7238f1b
local create = vide.create
local source = vide.source
@ -22,6 +28,30 @@ local function Counter()
end
```
```luau [Explicit Effect]
local create = vide.create
local source = vide.source
local effect = vide.effect
local function Counter()
local count = source(0)
local instance = create "TextButton" {
Activated = function()
count(count() + 1)
end
}
effect(function()
instance.Text = "count: " .. count()
end)
return instance
end
```
:::
This example is equivalent to the example seen on the previous page.
Instead of explicitly creating an effect, assigning a (non-event) property a
@ -46,12 +76,12 @@ local function List(props: { children: () -> { Instance } })
}
end
local list = List { children = items } -- creates a list with a single text label "A"
local list = List { children = items } -- creates a list with text label "A"
items {
create "TextLabel" { Text = "B" },
create "TextLabel" { Text = "C" }
}
-- this will automatically unparent the text label "A", and parent the labels "B" and "C"
-- this will automatically unparent text label "A", and parent labels "B" and "C"
```