Try improve crash course

This commit is contained in:
Aaron Smith 2023-11-21 18:48:47 +00:00
parent c288cb92c4
commit 338c66ed57
11 changed files with 223 additions and 102 deletions

View file

@ -2,9 +2,9 @@
Any reactive scopes created, such as by `effect()`, must be done so within a
"root" reactive scope. This is the main purpose of `mount()`, which you use
once at the top level to create your app as shown in the first introduction.
once at the top level to create your UI.
This is so that when the app is unmounted, it can clean up any reactive scopes
This is so that if you want to destroy your UI, it can stop any reactive scopes
created within it, since reactive scopes track any reactive scopes created
within them.
@ -53,16 +53,22 @@ The reactive graph for the above example looks like so:
graph
subgraph root["mount"]
subgraph root
direction LR
count --> effect
end
```
When the `mount` scope is destroyed, the `effect` scope will also be destroyed
since it was created within it.
When the root reactive scope created by `mount()` is destroyed, the `effect`
scope will also be destroyed since it was created within it.
This is important because you may have an effect that updates the property of a
UI instance, meaning the effect is referencing and holding that instance in
memory. The effect being destroyed will remove this reference, allowing the
instance to be garbage collected.
You don't need to worry about ensuring all your effects are created within a
root scope, since you should be creating all your UI and corresponding effects
within a top-level `mount()` call that puts all your UI together. So it is safe
to assume that any effect you create will be created under this top level scope.
Vide will prevent you from accidently doing otherwise anyways.