mirror of
https://github.com/centau/vide.git
synced 2026-08-20 14:41:37 +00:00
parent
71bbaa2092
commit
d1f86a3f9e
2 changed files with 13 additions and 11 deletions
|
|
@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- Reactive scopes created within reactive scopes are now destroyed on rerun.
|
- Reactive scopes created within reactive scopes are now destroyed on rerun.
|
||||||
|
- `untrack()` can be called outside of reactive scopes.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,21 +7,22 @@ local get_scope = graph.get_scope
|
||||||
|
|
||||||
local function untrack<T>(source: () -> T): T
|
local function untrack<T>(source: () -> T): T
|
||||||
local scope = get_scope()
|
local scope = get_scope()
|
||||||
if not scope then
|
|
||||||
throw("cannot untrack in non-reactive scope")
|
|
||||||
end; assert(scope)
|
|
||||||
|
|
||||||
-- sources are only tracked if the node in scope has an effect
|
if scope then
|
||||||
local effect = scope.effect
|
-- sources are only tracked if the node in scope has an effect
|
||||||
scope.effect = false
|
local effect = scope.effect
|
||||||
|
scope.effect = false
|
||||||
|
|
||||||
local ok, result = pcall(source)
|
local ok, result = pcall(source)
|
||||||
|
|
||||||
scope.effect = effect :: () -> ()
|
scope.effect = effect :: () -> ()
|
||||||
|
|
||||||
if not ok then error(result, 0) end
|
if not ok then error(result, 0) end
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
else
|
||||||
|
return source()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return untrack
|
return untrack
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue