@rbxts/rl 0.1.11 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/base_pesde.toml +1 -1
- package/build.luau +2 -2
- package/docs/api_ref.md +6 -15
- package/package.json +1 -1
- package/pesde.lock +11 -0
- package/src/init.luau +1 -1
- package/wally.toml +2 -2
- package/PESDE_README.md +0 -39
- package/publish.sh +0 -3
- /package/docs/{concepts.md → intro.md} +0 -0
package/README.md
CHANGED
package/base_pesde.toml
CHANGED
package/build.luau
CHANGED
|
@@ -4,7 +4,7 @@ local fs = require("@lune/fs")
|
|
|
4
4
|
local serde = require("@lune/serde")
|
|
5
5
|
|
|
6
6
|
local TARGETS = {"luau", "lune", "roblox"}
|
|
7
|
-
local INCLUDES = {"src", "COPYING", "
|
|
7
|
+
local INCLUDES = {"src", "COPYING", "README.md", "docs"}
|
|
8
8
|
|
|
9
9
|
local base_manifest = fs.readFile("base_pesde.toml")
|
|
10
10
|
|
|
@@ -19,7 +19,7 @@ for _, target in TARGETS do
|
|
|
19
19
|
fs.writeDir(out_dir)
|
|
20
20
|
|
|
21
21
|
for _, include in INCLUDES do
|
|
22
|
-
fs.copy(include, out_dir.."/"..
|
|
22
|
+
fs.copy(include, out_dir.."/"..include)
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
fs.writeFile(out_dir.."/pesde.toml", base_manifest.."\n"..serde.encode("toml", {target = {
|
package/docs/api_ref.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# rl API Reference
|
|
2
2
|
## Types
|
|
3
3
|
### state\<T>
|
|
4
|
-
The [state](https://pesde.dev/packages/wiam/rl/latest/any/docs/
|
|
4
|
+
The [state](https://pesde.dev/packages/wiam/rl/latest/any/docs/intro#state) type.
|
|
5
5
|
|
|
6
6
|
```luau
|
|
7
7
|
type state<T> = (() -> T) & ((value : T, force : boolean?) -> T) & {
|
|
@@ -10,7 +10,7 @@ type state<T> = (() -> T) & ((value : T, force : boolean?) -> T) & {
|
|
|
10
10
|
```
|
|
11
11
|
|
|
12
12
|
### callback
|
|
13
|
-
Function which gets called when its [effect](https://pesde.dev/packages/wiam/rl/latest/any/docs/
|
|
13
|
+
Function which gets called when its [effect](https://pesde.dev/packages/wiam/rl/latest/any/docs/intro#effect) is triggered.
|
|
14
14
|
Takes the previous value of the state which triggered the effect, as well as its "index", determined by the order in which it appears within the function.
|
|
15
15
|
|
|
16
16
|
```luau
|
|
@@ -19,12 +19,11 @@ type callback<T> = (old_value : T, state_i : number?) -> any
|
|
|
19
19
|
|
|
20
20
|
## Functions
|
|
21
21
|
### state
|
|
22
|
-
Creates a new [state](https://pesde.dev/packages/wiam/rl/latest/any/docs/
|
|
22
|
+
Creates a new [state](https://pesde.dev/packages/wiam/rl/latest/any/docs/intro#state), with the given initial value, and whether to always [force](https://pesde.dev/packages/wiam/rl/latest/any/docs/intro#forcing), and returns it.
|
|
23
23
|
|
|
24
24
|
```luau
|
|
25
25
|
function state<T>(value : T?, force : boolean?) : state<T>
|
|
26
26
|
|
|
27
|
-
-- Example
|
|
28
27
|
local health = state(100)
|
|
29
28
|
local stamina = state(100, true)
|
|
30
29
|
```
|
|
@@ -41,7 +40,6 @@ as how would happen with a function which's return value depends on a State.
|
|
|
41
40
|
```luau
|
|
42
41
|
function derive<T, U>(callback : () -> U) : (state<U>, () -> (), true)
|
|
43
42
|
|
|
44
|
-
-- Example
|
|
45
43
|
-- without derive() (normal function)
|
|
46
44
|
local half_health = function()
|
|
47
45
|
print("some computation")
|
|
@@ -65,12 +63,11 @@ print(derive_half_health()) -- 10
|
|
|
65
63
|
```
|
|
66
64
|
|
|
67
65
|
### effect
|
|
68
|
-
Creates a new [effect](https://pesde.dev/packages/wiam/rl/latest/any/docs/
|
|
66
|
+
Creates a new [effect](https://pesde.dev/packages/wiam/rl/latest/any/docs/intro#effect), with the given [callback](https://pesde.dev/packages/wiam/rl/latest/any/docs/api_ref#callback) function, and returns its disconnect function.
|
|
69
67
|
|
|
70
68
|
```luau
|
|
71
69
|
function effect<T>(callback : callback<T>) : () -> ()
|
|
72
70
|
|
|
73
|
-
-- Example
|
|
74
71
|
effect(function()
|
|
75
72
|
print(`new health: {health()}`)
|
|
76
73
|
end)
|
|
@@ -96,7 +93,6 @@ Batches any State write operation up until the function is done running.
|
|
|
96
93
|
```luau
|
|
97
94
|
function batch(f : () -> any) : ()
|
|
98
95
|
|
|
99
|
-
-- Example
|
|
100
96
|
batch(function()
|
|
101
97
|
health(420)
|
|
102
98
|
health(1337, true)
|
|
@@ -104,7 +100,6 @@ batch(function()
|
|
|
104
100
|
end)
|
|
105
101
|
|
|
106
102
|
-- "new health: 69"
|
|
107
|
-
|
|
108
103
|
```
|
|
109
104
|
|
|
110
105
|
### scope
|
|
@@ -115,7 +110,6 @@ This is intended to be used for disconnecting Effects in bulk.
|
|
|
115
110
|
```luau
|
|
116
111
|
function scope<T>(... : T) : () -> ()
|
|
117
112
|
|
|
118
|
-
-- Example
|
|
119
113
|
-- without scope
|
|
120
114
|
local disconnect_health = effect(function()
|
|
121
115
|
print(`your health is : {health()}`)
|
|
@@ -146,14 +140,13 @@ vitals_scope()
|
|
|
146
140
|
```
|
|
147
141
|
|
|
148
142
|
### branch
|
|
149
|
-
Alternative `if`-like function to be used within effects. Learn more about it in the [tracking section of the
|
|
143
|
+
Alternative `if`-like function to be used within effects. Learn more about it in the [tracking section of the intro page](https://pesde.dev/packages/wiam/rl/latest/any/docs/intro#tracking).
|
|
150
144
|
Pass a condition to be checked, and after it a function to be run if it's successful.
|
|
151
145
|
The last value, if a function, and if not after a condition, will be threated as the "else" branch.
|
|
152
146
|
|
|
153
147
|
```luau
|
|
154
148
|
function branch(...) : ()
|
|
155
149
|
|
|
156
|
-
-- Example
|
|
157
150
|
-- A single effect for the same functionality as the examples above, thanks to the use of state_i and the branching function.
|
|
158
151
|
effect(function(_, state_i)
|
|
159
152
|
branch(
|
|
@@ -175,7 +168,6 @@ Returns the given table, as well as a function which disconnects all created eff
|
|
|
175
168
|
```luau
|
|
176
169
|
function mirror<K, V>(t : {[K] : V}) : ({[K] : V}, () -> ())
|
|
177
170
|
|
|
178
|
-
-- Example
|
|
179
171
|
local name = state("john")
|
|
180
172
|
local data = mirror {
|
|
181
173
|
username = name,
|
|
@@ -191,12 +183,11 @@ print({data.username}) -- "joe"; didn't update because we disconnected the effec
|
|
|
191
183
|
```
|
|
192
184
|
|
|
193
185
|
### cleanup
|
|
194
|
-
Disconnects all [effects](https://pesde.dev/packages/wiam/rl/latest/any/docs/
|
|
186
|
+
Disconnects all [effects](https://pesde.dev/packages/wiam/rl/latest/any/docs/intro#effect).
|
|
195
187
|
|
|
196
188
|
```luau
|
|
197
189
|
function cleanup() : ()
|
|
198
190
|
|
|
199
|
-
-- Example
|
|
200
191
|
cleanup()
|
|
201
192
|
health(77) -- doesn't print because no effect is connected to this state (we just disconnected)
|
|
202
193
|
```
|
package/package.json
CHANGED
package/pesde.lock
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# This file is automatically @generated by pesde.
|
|
2
|
+
# It is not intended for manual editing.
|
|
3
|
+
format = 2
|
|
4
|
+
name = "wiam/rl_root"
|
|
5
|
+
version = "1.0.0"
|
|
6
|
+
target = "lune"
|
|
7
|
+
|
|
8
|
+
[workspace."wiam/rl"]
|
|
9
|
+
roblox = "build/roblox"
|
|
10
|
+
lune = "build/lune"
|
|
11
|
+
luau = "build/luau"
|
package/src/init.luau
CHANGED
|
@@ -171,7 +171,7 @@ end
|
|
|
171
171
|
|
|
172
172
|
@param callback () -> U -- the callback
|
|
173
173
|
@return derived_state state<U> -- the State that was created
|
|
174
|
-
@return disconnect () -> -- the created Effect's disconnect function
|
|
174
|
+
@return disconnect () -> () -- the created Effect's disconnect function
|
|
175
175
|
@return flag true -- a flag used internally by rl.scope(); can be ignored.
|
|
176
176
|
]=]
|
|
177
177
|
function rl.derive<T, U>(callback : () -> U) : (state<U>, () -> (), true)
|
package/wally.toml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "wiam77/rl"
|
|
3
|
-
description = "Simple reactive library for Luau. Docs: https://pesde.dev/packages/wiam/rl/latest/any/docs/
|
|
4
|
-
version = "0.1.
|
|
3
|
+
description = "Simple reactive library for Luau. Docs: https://pesde.dev/packages/wiam/rl/latest/any/docs/intro"
|
|
4
|
+
version = "0.1.13"
|
|
5
5
|
license = "GPL-3.0-or-later"
|
|
6
6
|
registry = "https://github.com/UpliftGames/wally-index"
|
|
7
7
|
realm = "shared"
|
package/PESDE_README.md
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
# rl
|
|
2
|
-
`rl` is a simple reactive library for Luau, inspired by [Vide](https://centau.github.io/vide)'s sources and effects system.
|
|
3
|
-
|
|
4
|
-
# API Reference
|
|
5
|
-
You can read `rl`'s API reference [here](https://pesde.dev/packages/wiam/rl/latest/any/docs/api_ref).
|
|
6
|
-
|
|
7
|
-
# Demo
|
|
8
|
-
```luau
|
|
9
|
-
--!strict
|
|
10
|
-
|
|
11
|
-
local rl = require("path/to/rl")
|
|
12
|
-
local s = rl.state
|
|
13
|
-
local e = rl.effect
|
|
14
|
-
|
|
15
|
-
local name = s("john", true)
|
|
16
|
-
local login_year = s(2020)
|
|
17
|
-
|
|
18
|
-
local login_d = e(function(last_login : number)
|
|
19
|
-
print(`{name.value}, it's been {login_year() - (last_login or 0)} years!`)
|
|
20
|
-
end)
|
|
21
|
-
|
|
22
|
-
login_year(2025) -- "wiam, it's been 5 years!"
|
|
23
|
-
login_year(2025) -- doesn't print because value didn't change
|
|
24
|
-
login_year(2025, true) -- "wiam, it's been 0 years!" - this prints since it's forced
|
|
25
|
-
|
|
26
|
-
name("doe") -- doesn't print because we are reading with name.value, and not name()
|
|
27
|
-
|
|
28
|
-
e(function(old_name : string)
|
|
29
|
-
print(`hey {old_name}, your name has been changed to '{name()}'`)
|
|
30
|
-
end)
|
|
31
|
-
|
|
32
|
-
name("jane") -- "hey doe, your name has been changed to jane"
|
|
33
|
-
name("jane") -- "hey jane, your name has been changed to jane" - this one is forced by default
|
|
34
|
-
|
|
35
|
-
login_d()
|
|
36
|
-
login_year(2026) -- doesn't print because the effect was disconnected
|
|
37
|
-
|
|
38
|
-
rl.cleanup() -- disconnect all effects
|
|
39
|
-
```
|
package/publish.sh
DELETED
|
File without changes
|