mirror of
https://github.com/centau/vide.git
synced 2026-08-20 14:41:37 +00:00
Update docs
This commit is contained in:
parent
9b6be14441
commit
46937c6979
16 changed files with 157 additions and 116 deletions
|
|
@ -1,8 +1,7 @@
|
|||
# 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.
|
||||
to run some code on an instance receiving them.
|
||||
|
||||
```lua
|
||||
local action = vide.action
|
||||
|
|
@ -20,24 +19,22 @@ create "TextLabel" {
|
|||
-- 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:
|
||||
Actions can be wrapped with functions for reuse. Below is an example of an
|
||||
action used to listen for property changes:
|
||||
|
||||
```lua
|
||||
local action = vide.action
|
||||
local cleanup = vide.cleanup
|
||||
|
||||
local function changed(property: string, callback: (new) -> ())
|
||||
local function changed(prop: string, callback: (new) -> ())
|
||||
return action(function(instance)
|
||||
local con = instance:GetPropertyChangedSignal(property):Connect(function()
|
||||
local connection = instance:GetPropertyChangedSignal(prop):Connect(function()
|
||||
callback(instance[property])
|
||||
end)
|
||||
|
||||
-- remember to clean up the connection when the reactive scope the action
|
||||
-- is ran in is destroyed, so the instance can be garbage collected
|
||||
cleanup(function()
|
||||
con:Disconnect()
|
||||
end)
|
||||
cleanup(connection)
|
||||
end)
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue