mirror of
https://github.com/centau/vide.git
synced 2026-08-20 14:41:37 +00:00
This commit is contained in:
parent
5a458eae71
commit
68ff117be9
19 changed files with 80 additions and 83 deletions
|
|
@ -3,7 +3,7 @@
|
|||
Instances are created using [`create()`](../../api/creation.md#create).
|
||||
|
||||
```lua
|
||||
local vide = require(path_to_vide)
|
||||
local vide = require(vide)
|
||||
local create = vide.create
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,10 @@ Components are custom-made reusable pieces of UI made from other pieces of UI.
|
|||
By using components you can make your application more modular and better
|
||||
organized.
|
||||
|
||||
```lua [Button.lua]
|
||||
```lua [Button.luau]
|
||||
local vide = require(vide)
|
||||
local create = vide.create
|
||||
|
||||
local function Button(props: {
|
||||
Position: UDim2,
|
||||
Text: string,
|
||||
|
|
@ -24,7 +27,10 @@ end
|
|||
return Button
|
||||
```
|
||||
|
||||
```lua [App.lua]
|
||||
```lua [App.luau]
|
||||
local vide = require(vide)
|
||||
local create = vide.create
|
||||
|
||||
local Button = require(Button)
|
||||
|
||||
local function App()
|
||||
|
|
@ -34,7 +40,7 @@ local function App()
|
|||
Text = "click me!",
|
||||
|
||||
Activated = function()
|
||||
print "clickeD"
|
||||
print "clicked"
|
||||
end
|
||||
}
|
||||
}
|
||||
|
|
@ -43,27 +49,17 @@ end
|
|||
root(App).Parent = game.StarterGui
|
||||
```
|
||||
|
||||
Above is a simple example of a button component with its background color set to
|
||||
a dark grey and with a fixed size.
|
||||
Above is a simple example of a button component with a set color and size,
|
||||
being reused across files.
|
||||
|
||||
A single parameter `props` is used to pass properties to the component.
|
||||
Creating instances of this button component is as simple as doing the below:
|
||||
|
||||
```lua
|
||||
local button = Button {
|
||||
Position = UDim2.new(),
|
||||
Text = "Click me!",
|
||||
|
||||
Activated = function()
|
||||
print "clicked"
|
||||
end
|
||||
}
|
||||
```
|
||||
|
||||
Components allow you to *encapsulate* behavior. You can only modify the
|
||||
component in ways that you allow in the component.
|
||||
|
||||
This also promotes code reusability. Anytime you want a new button all you do
|
||||
is call `Button {}` instead of creating and setting every property each time.
|
||||
When changing the button in future, any changes to the button file will be
|
||||
reflected anywhere the button is used throughout your app.
|
||||
|
||||
This can be extended to much more complicated UI.
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ A source in Vide can be created using
|
|||
|
||||
```lua
|
||||
local source = vide.source
|
||||
|
||||
local count = source(0)
|
||||
```
|
||||
|
||||
|
|
@ -24,7 +23,10 @@ count(count() + 1) -- increment source by 1
|
|||
|
||||
Below is an example of a stateful counter component.
|
||||
|
||||
```lua
|
||||
```lua [Counter.luau]
|
||||
local vide = require(vide)
|
||||
local source = vide.source
|
||||
|
||||
local function Counter(props: { Position: UDim2 })
|
||||
local count = source(0)
|
||||
|
||||
|
|
@ -54,22 +56,3 @@ This allows you as the programmer to not need to manually update GUI as the stat
|
|||
of your program changes. You just define how the data maps to UI, and Vide's
|
||||
reactive system will surgically update any properties depending on sources that
|
||||
are changed.
|
||||
|
||||
Since sources are just functions, you can also pass external sources to
|
||||
components like so:
|
||||
|
||||
```lua
|
||||
local function Text(p: {
|
||||
Text: () -> string
|
||||
})
|
||||
return create "TextLabel" {
|
||||
Text = p.Text
|
||||
}
|
||||
end
|
||||
|
||||
local text = source "hi"
|
||||
|
||||
Text {
|
||||
Text = text
|
||||
}
|
||||
```
|
||||
|
|
|
|||
0
docs/tut/crash-course/5-effect.md
Normal file
0
docs/tut/crash-course/5-effect.md
Normal file
|
|
@ -63,7 +63,7 @@ callback when deriving or binding sources. If a source is in a function but is
|
|||
never referenced the first time it runs, Vide will not know to rerun the
|
||||
function if that source changes.
|
||||
|
||||
An example to watch out for is when using sources within branches:
|
||||
An example to effect out for is when using sources within branches:
|
||||
|
||||
```lua
|
||||
local condition = source(true)
|
||||
0
docs/tut/crash-course/8-cleanup.md
Normal file
0
docs/tut/crash-course/8-cleanup.md
Normal file
Loading…
Add table
Add a link
Reference in a new issue