mirror of
https://github.com/centau/vide.git
synced 2026-08-20 14:41:37 +00:00
Limit cleanup() calls to once per scope
This commit is contained in:
parent
2aebaf5abb
commit
0105e33fac
5 changed files with 63 additions and 5 deletions
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
## cleanup()
|
||||
|
||||
Runs a callback anytime a reactive scope is re-ran.
|
||||
Runs a callback anytime a function scope is re-ran.
|
||||
|
||||
- **Type**
|
||||
|
||||
|
|
@ -10,6 +10,19 @@ Runs a callback anytime a reactive scope is re-ran.
|
|||
function cleanup(callback: () -> ())
|
||||
```
|
||||
|
||||
- **Details**
|
||||
|
||||
The primary purpose of this function is to provide a means of cleaning up
|
||||
side effects caused by source updates and `watch()` updates.
|
||||
|
||||
The stack is inspected to find the function that calls `cleanup()`. The
|
||||
callback passed is called anytime the caller is re-ran, and when the caller
|
||||
finally garbage collects.
|
||||
|
||||
::: warning
|
||||
Only one `cleanup()` call is allowed per function scope.
|
||||
:::
|
||||
|
||||
- **Example**
|
||||
|
||||
```lua
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ Currently, strict mode will:
|
|||
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.
|
||||
This also helps ensure that cleanups are being handled correctly.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue