This commit is contained in:
Aaron Smith 2023-09-12 17:55:54 +01:00
parent 5a458eae71
commit 68ff117be9
19 changed files with 80 additions and 83 deletions

View file

@ -50,16 +50,16 @@ Creates a new source with the given value.
count(count() + 1) -- 1
```
## watch()
## effect()
Runs a callback on source update.
- **Type**
```lua
function watch(source: () -> ()): Unwatch
function effect(source: () -> ()): Uneffect
type Unwatch = () -> ()
type Uneffect = () -> ()
```
- **Details**
@ -70,7 +70,7 @@ Runs a callback on source update.
Any time a source referenced in the callback is changed, the callback will
be reran.
Also returns a function that when called, stops the watcher immediately.
Also returns a function that when called, stops the effecter immediately.
::: warning
`source()` cannot yield.
@ -81,7 +81,7 @@ Runs a callback on source update.
```lua
local state = source(1)
watch(function()
effect(function()
print(state())
end)

View file

View file

@ -15,7 +15,7 @@ Runs a callback anytime a reactive scope is re-ran.
```lua
local data = source(1)
watch(function()
effect(function()
local label = create "TextLabel" { Text = data() }
cleanup(function()

View file

@ -12,14 +12,14 @@ and identifying improper usage.
Currently, strict mode will:
1. Run derived sources twice a source updates.
2. Run watchers twice when a source updates.
2. Run effecters twice when a source updates.
3. Throw an error if yields occur where they are not allowed.
4. Checks for `indexes()` and `values()` returning primitive values.
5. Checks for duplicate nested properties at same depth.
6. Better error reporting and stack traces.
7. Checks for multiple `cleanup()` calls in the same function scope.
By rerunning sources and watchers, any side-effects are made more apparent.
By rerunning sources and effecters, any side-effects are made more apparent.
This also helps ensure that cleanups are being handled correctly.
Accidental yielding within reactive scopes can break Vide's reactive graph,