Owns effects, computeds and adopted objects; destroys them in reverse creation order.
More...
|
| | Scope (Runtime &runtime, std::size_t depth=0) noexcept |
| | Constructs a scope.
|
| | ~Scope () |
| | Destroys everything owned, newest first, and tells every make() still constructing that the scope is gone.
|
|
| Scope (Scope const &)=delete |
|
Scope & | operator= (Scope const &)=delete |
|
| Scope (Scope &&)=delete |
|
Scope & | operator= (Scope &&)=delete |
| template<typename T, typename... Args> |
| T & | make (Args &&... args) |
| | Constructs a T from args and owns it.
|
| template<typename T> |
| T & | adopt (std::unique_ptr< T > owned) |
| | Takes ownership of owned.
|
| template<typename F> |
| Effect & | effect (F &&fn) |
| | Makes an Effect owned by this scope, at this scope's depth.
|
| Scope & | child () |
| | Makes a scope one level deeper, owned by this one.
|
| template<typename F> |
| auto & | computed (F &&fn) |
| | Makes a Computed owned by this scope; its type is what fn returns.
|
| void | clear () noexcept |
| | Destroys everything owned, newest first.
|
| std::size_t | size () const noexcept |
| | How many objects the scope owns.
|
| Runtime & | runtime () const noexcept |
| | The runtime.
|
| std::size_t | depth () const noexcept |
| | How deeply this scope is nested.
|
Owns effects, computeds and adopted objects; destroys them in reverse creation order.
A mounted view, a Switch case and a ForEach row each own one, so tearing one down stops every binding it made before anything those bindings point at goes away.
Scopes nest: a scope made by child() is one level deeper, and the Effects a scope makes carry its depth. Queued Effects run shallowest first, so an owner's Effects run before those of the scopes it owns, whatever order the writes came in and whichever Effect was made first: a row binding never evaluates against a parent that is about to remove the row.
An Effect the scope owns may clear or destroy the scope from its own body (a remount): the graph keeps the running body alive, and the body must not touch the scope or anything it owned afterwards. That holds for an Effect's first run too, which happens inside effect() before the scope stores it:
- If the first run clears the scope, the new Effect is stored after the clear and stays.
- If it destroys the scope, the new Effect is destroyed at once, since a dead scope owns nothing, and the reference effect() returns dangles (as does every reference to an object the scope owned). That destructor runs after the scope is gone, so it must not use the scope.
Only the nodes check the owner (detail::site::kOffOwner); the scope's own list is unguarded. Using a scope off its Runtime's owner is a misuse that is not reported.
An owned object's destructor may call back into the scope. It leaves the list before it is destroyed. A destructor that keeps calling make() while the scope is clearing never lets clear() finish.
Definition at line 44 of file scope.hpp.