mirror of
https://github.com/centau/vide.git
synced 2026-08-20 14:41:37 +00:00
This commit is contained in:
parent
52ea2e4690
commit
5b61a9df10
13 changed files with 57 additions and 39 deletions
|
|
@ -2,6 +2,26 @@
|
|||
|
||||
<br/>
|
||||
|
||||
## root()
|
||||
|
||||
Creates and runs a function in a new reactive scope.
|
||||
|
||||
- **Type**
|
||||
|
||||
```lua
|
||||
function root<T>(fn: () -> T): (T, () -> ())
|
||||
```
|
||||
|
||||
- **Details**
|
||||
|
||||
Creates a new root reactive scope, where creation and derivations of sources
|
||||
can be tracked and properly disposed of.
|
||||
|
||||
Returns the result of the given function.
|
||||
|
||||
Also returns a function to destroy the root, which will run any cleanups
|
||||
and allow derived sources created to garbage collect.
|
||||
|
||||
## source()
|
||||
|
||||
Creates a new source with the given value.
|
||||
|
|
@ -14,10 +34,10 @@ Creates a new source with the given value.
|
|||
|
||||
- **Details**
|
||||
|
||||
Calling the returned source with no arguments will return its stored value,
|
||||
calling with arguments will set a new value.
|
||||
Calling the returned source with no argument will return its stored value,
|
||||
calling with an argument will set a new value.
|
||||
|
||||
Reading from the source from within any reactive scope will cause changes
|
||||
Reading from the source from within a reactive scope will cause changes
|
||||
to that source to be tracked and anything depending on it to update.
|
||||
|
||||
- **Example**
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
## cleanup()
|
||||
|
||||
Runs a callback anytime a function scope is re-ran.
|
||||
Runs a callback anytime a reactive scope is re-ran.
|
||||
|
||||
- **Type**
|
||||
|
||||
|
|
@ -10,19 +10,6 @@ Runs a callback anytime a function 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
|
||||
|
|
@ -53,7 +40,7 @@ Runs a callback anytime a function scope is re-ran.
|
|||
|
||||
## untrack()
|
||||
|
||||
Gets the value of a source without reactively tracking it.
|
||||
Runs a given function where any sources read will not track its reactive scope.
|
||||
|
||||
- **Type**
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
This is a brief tutorial designed to give you a quick run through the usage of
|
||||
Vide.
|
||||
|
||||
Vide is largely inspired by other UI libraries such as Solid and Fusion.
|
||||
Vide is heavily inspired by [Solid](https://www.solidjs.com/).
|
||||
|
||||
## Why Vide?
|
||||
|
||||
|
|
@ -21,5 +21,6 @@ Some of the main focuses behind Vide's design choices:
|
|||
- Being completely typecheckable.
|
||||
- Flexibility, particularly with integrating other libraries and allowing users
|
||||
to use their own patterns.
|
||||
- A powerful reactive system that does not interfere with the lifetime of
|
||||
instances.
|
||||
- Independence from instance lifetimes.
|
||||
- A powerful reactive system that can surgically update properties as a result
|
||||
of state changes.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue