mirror of
https://github.com/centau/vide.git
synced 2026-08-20 23:01:37 +00:00
Fix mistakes in docs
This commit is contained in:
parent
baf308ccf3
commit
bacb4fa0f0
8 changed files with 12 additions and 18 deletions
|
|
@ -65,7 +65,7 @@ export default withMermaid({
|
||||||
{
|
{
|
||||||
text: "Dynamic Scoping",
|
text: "Dynamic Scoping",
|
||||||
items: [
|
items: [
|
||||||
{ text: "Custom Scopes", link: "/tut/dynamic-scoping/custom"}
|
{ text: "Custom Scopes", link: "/tut/advanced/custom"}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ Shows one of a set of components depending on a source and a mapping table.
|
||||||
- **Type**
|
- **Type**
|
||||||
|
|
||||||
```luau
|
```luau
|
||||||
function switch<K, V>(source: () -> K): (map: Map<K, () -> V>) () -> V?
|
function switch<K, V>(source: () -> K): (map: Map<K, () -> V>): () -> V?
|
||||||
```
|
```
|
||||||
|
|
||||||
- **Details**
|
- **Details**
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ as a guard against unintentional rerendering of UI.
|
||||||
|
|
||||||
## Recreating [`switch()`](/api/reactivity-dynamic#switch-reactive)
|
## Recreating [`switch()`](/api/reactivity-dynamic#switch-reactive)
|
||||||
|
|
||||||
```lua
|
```luau
|
||||||
local function switch(key)
|
local function switch(key)
|
||||||
return function(map)
|
return function(map)
|
||||||
return derive(function()
|
return derive(function()
|
||||||
|
|
@ -76,7 +76,7 @@ between reruns, we cannot use `untrack()` anymore which automatically destroys
|
||||||
on rerun; we must use `root()` where the lifetime of each scope is managed
|
on rerun; we must use `root()` where the lifetime of each scope is managed
|
||||||
manually and independently.
|
manually and independently.
|
||||||
|
|
||||||
```lua
|
```luau
|
||||||
local function indexes<I, VI, VO>(
|
local function indexes<I, VI, VO>(
|
||||||
input: () -> Map<I, VI>,
|
input: () -> Map<I, VI>,
|
||||||
transform: (value: () -> VI, index: I) -> VO
|
transform: (value: () -> VI, index: I) -> VO
|
||||||
|
|
@ -26,9 +26,9 @@ local source = vide.source
|
||||||
local effect = vide.effect
|
local effect = vide.effect
|
||||||
local cleanup = vide.cleanup
|
local cleanup = vide.cleanup
|
||||||
|
|
||||||
local function changed(prop: string, callback: (new) -> ())
|
local function changed(property: string, callback: (new) -> ())
|
||||||
return action(function(instance)
|
return action(function(instance)
|
||||||
local connection = instance:GetPropertyChangedSignal(prop):Connect(function()
|
local connection = instance:GetPropertyChangedSignal(property):Connect(function()
|
||||||
callback(instance[property])
|
callback(instance[property])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ local count = source(0)
|
||||||
|
|
||||||
root(function()
|
root(function()
|
||||||
local text = derive(function()
|
local text = derive(function()
|
||||||
return "count: " .. text()
|
return "count: " .. count()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
effect(function()
|
effect(function()
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ effects depending on it.
|
||||||
|
|
||||||
You can also read from a source within an effect without the effect tracking it.
|
You can also read from a source within an effect without the effect tracking it.
|
||||||
|
|
||||||
```lua
|
```luau
|
||||||
local source = vide.source
|
local source = vide.source
|
||||||
local effect = vide.effect
|
local effect = vide.effect
|
||||||
local untrack = vide.untrack
|
local untrack = vide.untrack
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,6 @@ local function setup()
|
||||||
effect(function()
|
effect(function()
|
||||||
print(count())
|
print(count())
|
||||||
end)
|
end)
|
||||||
|
|
||||||
return count
|
|
||||||
end
|
end
|
||||||
|
|
||||||
setup() -- error, effect() tried to create a reactive scope with no stable scope
|
setup() -- error, effect() tried to create a reactive scope with no stable scope
|
||||||
|
|
|
||||||
|
|
@ -34,14 +34,10 @@ count source is created inside the component.
|
||||||
External sources can also be passed into components for them to use.
|
External sources can also be passed into components for them to use.
|
||||||
|
|
||||||
```luau
|
```luau
|
||||||
local function Counter(props: { count: () -> number })
|
local function CountDisplay(props: { count: () -> number })
|
||||||
local count = props.count
|
local count = props.count
|
||||||
|
|
||||||
local instance = create "TextButton" {
|
local instance = create "TextLabel" {}
|
||||||
Activated = function()
|
|
||||||
count(count() + 1)
|
|
||||||
end
|
|
||||||
}
|
|
||||||
|
|
||||||
effect(function()
|
effect(function()
|
||||||
instance.Text = "count: " .. count()
|
instance.Text = "count: " .. count()
|
||||||
|
|
@ -52,11 +48,11 @@ end
|
||||||
|
|
||||||
local count = source(0)
|
local count = source(0)
|
||||||
|
|
||||||
Counter {
|
CountDisplay {
|
||||||
count = count
|
count = count
|
||||||
}
|
}
|
||||||
|
|
||||||
count(1) -- the Counter component will update to display this count
|
count(1) -- the CountDisplay component will update to display this count
|
||||||
```
|
```
|
||||||
|
|
||||||
Sources can be created internally or passed in from externally, there are no
|
Sources can be created internally or passed in from externally, there are no
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue