-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* complete overhaul * changed wally.toml
- Loading branch information
Showing
26 changed files
with
363 additions
and
1,018 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,10 @@ | ||
# Project place file | ||
/accord.rbxlx | ||
/*.rbxl | ||
/*.rbxlx | ||
|
||
# Roblox Studio lock files | ||
/*.rbxlx.lock | ||
/*.rbxl.lock | ||
|
||
/*.rbxl | ||
/*.rbxlx.lock | ||
|
||
/Packages | ||
/DevPackages | ||
/client | ||
|
||
wally.lock | ||
|
||
|
||
/out | ||
/node_modules | ||
/.vscode |
This file was deleted.
Oops, something went wrong.
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,3 @@ | ||
{ | ||
"languageMode": "strict" | ||
} |
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,62 +1,36 @@ | ||
<div align="center">⚠️Repo is in development, EVERYTHING is subject to change, until v1.0.0⚠️</div> | ||
<br> | ||
|
||
<p align="center" width="100%"> | ||
<img src="./assets/logo.png"> | ||
<p align="center""> | ||
<img src="./assets/logo.png" width="450" /> | ||
</p> | ||
<div align="center">⚠️Library is in development, EVERYTHING is subject to change until v1.0.0⚠️</div> | ||
<br> | ||
|
||
## Example | ||
```lua | ||
local accord = require("path to accord") | ||
|
||
local balance = accord:NewState(0) { | ||
Add = function(self, num: number) | ||
self.value += num | ||
end, | ||
|
||
Sub = function(self, num: number) | ||
self.value -= num | ||
end, | ||
} | ||
-- basic example | ||
local num = Accord.new(0, Guard.Number) | ||
|
||
balance:Add(1) | ||
|
||
-- by default, :Connect is defered, and in this | ||
-- example, it will only print '3' one time | ||
balance:Connect(function() | ||
print(balance:Get()) | ||
num:Connect(function(value, oldValue) | ||
print(`num changed from {oldValue} to {value}`) | ||
end) | ||
|
||
balance:Add(1) | ||
balance:Add(1) | ||
``` | ||
|
||
## API | ||
|
||
`Accord` | ||
```lua | ||
Accord:NewState<T>(defaultValue: T, config: Config?): <S>(methods: S | Methods<T>) -> State<T> & S | ||
-- Creates a new state. | ||
``` | ||
-- react hook example | ||
return function<T>(value: Accord.Accord<T>): T | ||
local state, setState = React.useState(value:get()) | ||
|
||
`State<T>` | ||
```lua | ||
State:Get(): T | ||
-- Gets the value of the state. | ||
``` | ||
```lua | ||
State:Connect(callback: (): nil): Connection | ||
-- Connects a callback to when the state value changes. | ||
``` | ||
```lua | ||
State:ConnectOnce(callback: (): nil): Connection | ||
-- Connects a callback to when the state value changes once. | ||
``` | ||
```lua | ||
State:DisconnectAll(): nil | ||
-- Disconnects all connections to the state. | ||
React.useEffect(function() | ||
local connection = value:connect(setState) | ||
|
||
return function() | ||
connection:disconnect() | ||
end | ||
end, { value }) | ||
|
||
return state | ||
end | ||
``` | ||
|
||
## License | ||
|
||
Distributed under the MIT License. See [LICENSE](./LICENSE) for more information. | ||
Distributed under the MIT License. See [LICENSE](./LICENSE) for more information. |
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,10 @@ | ||
# This file lists tools managed by Aftman, a cross-platform toolchain manager. | ||
# For more information, see https://github.com/LPGhatguy/aftman | ||
|
||
# To add a new tool, add an entry to this table. | ||
[tools] | ||
StyLua = "JohnnyMorganz/StyLua@0.18.2" | ||
luau-lsp = "JohnnyMorganz/luau-lsp@1.25.0" | ||
selene = "Kampfkarren/selene@0.25.0" | ||
rojo = "UpliftGames/rojo@7.3.0-uplift.12.pre.8" | ||
wally = "UpliftGames/wally@0.3.2" |
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,6 +1,6 @@ | ||
{ | ||
"name": "accord", | ||
"tree": { | ||
"$path": "src" | ||
"$path": "lib" | ||
} | ||
} |
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,81 @@ | ||
local Signal = require(script.Parent.Signal) | ||
local Symbol = require(script.Parent.Symbol) | ||
|
||
-- TODO: figure out a better name for this. | ||
type AccordMain<T> = { | ||
value: T, | ||
guard: (value: unknown) -> T, | ||
|
||
_signal: Signal.Signal<(T, T)>, | ||
} | ||
|
||
type AccordImpl<T> = { | ||
set: (self: Accord<T>, value: T | (value: T) -> T) -> (), | ||
get: (self: Accord<T>) -> T, | ||
forceUpdate: (self: Accord<T>) -> (), | ||
|
||
connect: (self: Accord<T>, fn: (value: T) -> ()) -> Signal.Connection<T>, | ||
once: (self: Accord<T>, fn: (value: T) -> ()) -> Signal.Connection<T>, | ||
disconnectAll: (self: Accord<T>) -> (), | ||
} | ||
|
||
export type Accord<T> = typeof(setmetatable({} :: AccordMain<T>, {} :: { __index: AccordImpl<T> })) | ||
|
||
local module: AccordImpl<unknown> = {} :: AccordImpl<unknown> | ||
|
||
function module:set(value) | ||
local oldValue = self.value | ||
|
||
local v = if typeof(value) == "function" then (value :: any)(oldValue) else value | ||
|
||
if v == Symbol.abort then | ||
return | ||
end | ||
|
||
self.value = self.guard(v) | ||
|
||
self._signal:fire(self.value, oldValue) | ||
end | ||
|
||
function module:get() | ||
return self.value | ||
end | ||
|
||
function module:forceUpdate() | ||
self._signal:fire(self.value, self.value) | ||
end | ||
|
||
function module:connect(fn) | ||
return self._signal:connect(fn) | ||
end | ||
|
||
function module:once(fn) | ||
return self._signal:once(fn) | ||
end | ||
|
||
function module:disconnectAll() | ||
self._signal:disconnectAll() | ||
end | ||
|
||
local constructors = { | ||
new = function<T>(value: T, guard: (value: unknown) -> T): Accord<T> | ||
local self = { | ||
value = guard(value), | ||
guard = guard, | ||
|
||
_signal = Signal.new(), | ||
} | ||
|
||
return setmetatable(self, { __index = module }) :: any | ||
end, | ||
|
||
is = function<T>(value: Accord<T>): boolean | ||
if typeof(value) ~= "table" then | ||
return false | ||
end | ||
|
||
return getmetatable(value) == module | ||
end, | ||
} | ||
|
||
return constructors |
Oops, something went wrong.