mirror of
https://github.com/centau/vide.git
synced 2026-08-20 14:41:37 +00:00
Make root() return destructor automatically
This commit is contained in:
parent
8142acd1c1
commit
82eec61c45
8 changed files with 26 additions and 30 deletions
|
|
@ -43,21 +43,20 @@ local count = root(setup) -- ok since effect() was called within a stable scope
|
|||
count(1) -- prints "1"
|
||||
```
|
||||
|
||||
The scope created by `root()` can be destroyed by calling the function it passes
|
||||
into the given function.
|
||||
The scope created by `root()` can be destroyed.
|
||||
|
||||
```lua
|
||||
local function setup(destroy)
|
||||
local function setup()
|
||||
local count = source(0)
|
||||
|
||||
effect(function()
|
||||
print(count())
|
||||
end)
|
||||
|
||||
return count, destroy
|
||||
return count
|
||||
end
|
||||
|
||||
local count, destroy = root(setup)
|
||||
local destroy, count = root(setup)
|
||||
|
||||
count(1) -- prints "1"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue