mirror of
https://github.com/centau/vide.git
synced 2026-08-20 14:41:37 +00:00
Make changed() run initially
This commit is contained in:
parent
46937c6979
commit
c03fb05779
4 changed files with 24 additions and 1 deletions
|
|
@ -17,6 +17,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||
|
||||
- Reactive scopes created within reactive scopes are now destroyed on rerun.
|
||||
- `untrack()` can be called outside of reactive scopes.
|
||||
- `changed()` will also run its callback with the initial property value.
|
||||
|
||||
### Fixed
|
||||
|
||||
|
|
|
|||
|
|
@ -154,3 +154,23 @@ instances.
|
|||
changed("Text", output)
|
||||
}
|
||||
```
|
||||
|
||||
## changed()
|
||||
|
||||
A wrapper for `action()` to listen for property changes.
|
||||
|
||||
- **Type**
|
||||
|
||||
```lua
|
||||
function changed(property: string, callback: (...unknown) -> ()): Action
|
||||
```
|
||||
|
||||
- **Details**
|
||||
|
||||
Will run the given callback any time the property is changed, as well as
|
||||
when the action is initially run.
|
||||
|
||||
The changed connection is disconnected when the reactive scope the action is
|
||||
ran in is destroyed.
|
||||
|
||||
Runs with an action priority of 1.
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ local function changed<T>(property: string, callback: (T) -> ())
|
|||
cleanup(function()
|
||||
con:Disconnect()
|
||||
end)
|
||||
|
||||
callback((instance :: any)[property])
|
||||
end)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1806,7 +1806,7 @@ TEST("changed()", wrap_root(function()
|
|||
changed("Text", output)
|
||||
}
|
||||
|
||||
--CHECK(output() == "a")
|
||||
CHECK(output() == "a")
|
||||
text.Text = "b"
|
||||
CHECK(output() == "b")
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue