-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
223 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,25 @@ | ||
# Introduction | ||
|
||
This is a brief tutorial designed to give you a quick run through the usage of | ||
Vide. | ||
This is a tutorial that introduces the concepts and usage of Vide. | ||
|
||
Vide is heavily inspired by [Solid](https://www.solidjs.com/). | ||
|
||
This tutorial assumes familiarity with Luau and Roblox GUI. | ||
This tutorial assumes familiarity with Luau and Roblox UI. | ||
|
||
## Why Vide? | ||
|
||
Creating UI is a slow and tedious process. The purpose of Vide is to make UI | ||
declarative and concise, making it faster to create and more importantly easier | ||
to maintain. Vide achieves this using a reactive style of programming which | ||
allows you to focus on the flow of data through your application without | ||
worrying about manually updating UI instances. | ||
Creating UI is complicated, slow, and tedious. | ||
|
||
Some of the main focuses behind Vide's design choices: | ||
|
||
- Concise syntax. | ||
- Being completely typecheckable. | ||
- Independence from instance lifetimes. | ||
- Real reactivity. | ||
|
||
## Structure Of A Vide App | ||
Vide tries to simplify and speed up this process by providing a declarative and | ||
reactive of style programming, which lets you focus more on designing the UI | ||
itself and not having to manually update or reparent UI instances. | ||
|
||
The entry point for all Vide apps is the `mount()` function. This function | ||
sets up Vide's reactivity system. It takes and calls a function that should | ||
create your entire app, and will apply its result to a target. | ||
|
||
In Vide, your app should be composed of functions, each function creates a | ||
specific part of your app, and can be reused if needed. These functions are | ||
called *components*. | ||
Some of the main focuses behind Vide's design choices: | ||
|
||
```lua | ||
local function App() | ||
return { | ||
PlayerStats(), | ||
Inventory(), | ||
Settings() | ||
} | ||
end | ||
- Minimal syntax. | ||
- Complete typechecking | ||
- Independence from instances. | ||
|
||
mount(App, game.StarterGui) | ||
``` | ||
As with most declarative libraries, there is an initial learning curve to | ||
understand the concepts and usage. This tutorial tries to comprehensively | ||
cover these concepts and usage, more so than you need just to use it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
# Concepts Summary | ||
|
||
A summary of all the concepts covered during the crash course. | ||
|
||
## Source | ||
|
||
A source of data. | ||
|
||
Stores a single value that can be updated by the user. | ||
|
||
## Effect | ||
|
||
Anything that happens in reponse to a source update. | ||
|
||
Vide has built-in functions to create effects such as | ||
|
||
- `effect()` - runs arbitrary user code on source update | ||
- `derive()` - updates a derived source on source update | ||
|
||
## Reactive Scope | ||
|
||
A scope created by certain Vide functions where source updates can be tracked, | ||
and cleanups queued. | ||
|
||
When a source used inside a reactive scope is updated, the reactive scope will | ||
rerun. | ||
|
||
Reactive scopes are created by functions such as | ||
|
||
- `root()` | ||
- `effect()` | ||
- `derive()` | ||
|
||
## Owner | ||
|
||
A reactive scope created within an outer reactive scope, is *owned* by the outer | ||
reactive scope. | ||
|
||
When a reactive scope is re-ran or destroyed, all reactive scopes owned by it | ||
are also destroyed. | ||
|
||
Vide does not let you create reactive scopes without owners. | ||
|
||
## Root Reactive Scope | ||
|
||
A top-level reactive scope. These scopes are an exception to the owner rule. | ||
|
||
Created by `root()`, which `mount()` uses internally. | ||
|
||
A root reactive scope can be created on its own. It allows other reactive scopes | ||
to be created with an owner. | ||
|
||
Root reactive scopes must be destroyed manually by the user, a function to do | ||
this is given by `root()`. | ||
|
||
A root reactive scope can be created within another reactive scope and it will | ||
not automatically be owned by that scope. | ||
|
||
## Cleanup | ||
|
||
Cleans up the result from an effect. | ||
|
||
Unneeded in most cases, a cleanup is arbitrary code that can be ran before | ||
a reactive scope is rerun or destroyed, so that the result from the previous | ||
run can be cleaned up. A cleanup can be queued by using `cleanup()` within | ||
a reactive scope. | ||
|
||
## Tracking | ||
|
||
Reactive scopes are tracking by default, meaning sources read from within scope | ||
will be tracked. | ||
|
||
A reactive scope can be made temporarily non-tracking within `untrack()`, so | ||
that any source used will be ignored. The only function that creates a | ||
nontracking reactive scope by default is `root()`. | ||
|
||
## Reactive Graph | ||
|
||
The combination of reactive scopes can viewed graphically, called a | ||
*reactive graph*. This can be a more intuitive way to think of the | ||
relationships between effects and the sources they depend on. | ||
|
||
### Code | ||
|
||
```lua | ||
local count = source(0) | ||
|
||
root(function() | ||
local text = derive(function() | ||
return "count: " .. text() | ||
end) | ||
|
||
effect(function() | ||
print(text()) | ||
end) | ||
end) | ||
``` | ||
|
||
### Graph resulting from code | ||
|
||
```mermaid | ||
%%{init: { | ||
"theme": "base", | ||
"themeVariables": { | ||
"primaryColor": "#1B1B1F", | ||
"primaryTextColor": "#fff", | ||
"primaryBorderColor": "#1B1B1F", | ||
"lineColor": "#79B8FF", | ||
"tertiaryColor": "#161618", | ||
"tertiaryBorderColor": "#1C1C1F" | ||
} | ||
}}%% | ||
graph LR | ||
subgraph root | ||
text --> effect | ||
end | ||
count --> text | ||
``` | ||
|
||
Notes: | ||
|
||
- Since `count` is a source, not an effect, it can exist | ||
outside of a root reactive scope. | ||
- An update to `count` will cause `text` to rerun, which | ||
then causes `effect` to rerun. | ||
- When the root reactive scope is destroyed, `text` and | ||
`effect` will be destroyed alongside it, since they are | ||
owned by it. `count` will be untouched and future updates | ||
to `count` will have no effect. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.