mirror of
https://github.com/centau/vide.git
synced 2026-08-20 14:41:37 +00:00
43 lines
973 B
Markdown
43 lines
973 B
Markdown
# Actions
|
|
|
|
Actions in Vide are special callbacks that you can pass along with properties,
|
|
which will be called when those properties are being processed with the instance
|
|
being assigned to, allowing you to run custom code.
|
|
|
|
```lua
|
|
local action = vide.action
|
|
```
|
|
|
|
```lua
|
|
create "TextLabel" {
|
|
Text = "test",
|
|
|
|
action(function(instance)
|
|
print(instance.Text)
|
|
end)
|
|
}
|
|
|
|
-- will print "test"
|
|
```
|
|
|
|
Actions can be wrapped with functions to re-use specific behaviors. Below is
|
|
an example of an action used to listen for property changes:
|
|
|
|
```lua
|
|
local function changed(property: string, callback: (new) -> ())
|
|
return action(function(instance)
|
|
instance:GetPropertyChangedSignal(property):Connect(function()
|
|
callback(instance[property])
|
|
end)
|
|
end)
|
|
end
|
|
|
|
local output = source ""
|
|
|
|
create "TextBox" {
|
|
changed("Text", output)
|
|
}
|
|
```
|
|
|
|
The source `output` will be updated with the new property value any time it is
|
|
changed externally.
|