mirror of
https://github.com/centau/vide.git
synced 2026-08-20 23:01:37 +00:00
39 lines
616 B
Markdown
39 lines
616 B
Markdown
# Reactivity API: Utility
|
|
|
|
## cleanup()
|
|
|
|
Runs a callback anytime a reactive scope is re-ran.
|
|
|
|
- **Type**
|
|
|
|
```lua
|
|
function cleanup(callback: () -> ())
|
|
```
|
|
|
|
- **Example**
|
|
|
|
```lua
|
|
local data = source(1)
|
|
|
|
watch(function()
|
|
local label = create "TextLabel" { Text = data() }
|
|
|
|
cleanup(function()
|
|
label:Destroy()
|
|
end)
|
|
end)
|
|
```
|
|
|
|
```lua
|
|
local data = source(1)
|
|
|
|
derive(function()
|
|
local label = create "TextLabel" { Text = data() }
|
|
|
|
cleanup(function()
|
|
label:Destroy()
|
|
end)
|
|
|
|
return label
|
|
end)
|
|
```
|