refactor!: design overhaul (#1)

* refactor!: use atom functions

* docs: reformat api reference

* docs: showcase atom functions

* docs: remove unused import

* refactor: finalize updates

* chore: misc edits
This commit is contained in:
richard 2024-03-25 19:53:28 -07:00 • committed by GitHub
parent 4d4979daa9
commit 33ecae2f50
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
39 changed files with 577 additions and 729 deletions

View file

@ -2,43 +2,48 @@ local validate = require(script.Parent.validate)
local NONE = { __none = "__none" }
local function diff(previousState: { [any]: any }, nextState: { [any]: any })
local patch = table.clone(nextState)
local warnings = {}
for key, previous in previousState do
local function diff(prevState: { [any]: any }, nextState: { [any]: any })
local patches = table.clone(nextState)
for key, previous in prevState do
local next = nextState[key]
if previous == next then
patch[key] = nil
patches[key] = nil
elseif next == nil then
patch[key] = NONE
patches[key] = NONE
elseif type(previous) == "table" and type(next) == "table" then
patch[key] = diff(previous, next)
patches[key] = diff(previous, next)
end
end
if _G.__DEV__ then
local success, result = pcall(function()
for key, value in previousState do
for key, value in prevState do
validate(value, key)
end
for key, value in nextState do
validate(value, key)
if prevState[key] ~= value then
validate(value, key)
end
end
end)
if not success then
if not success and not warnings[result] then
warnings[result] = true
warn(result)
end
end
return patch
return patches
end
local function apply(state: { [any]: any }, patchState: { [any]: any })
local function apply(state: { [any]: any }, patches: { [any]: any })
local nextState = table.clone(state)
for key, patch in patchState do
for key, patch in patches do
local current = nextState[key]
if type(patch) == "table" and patch.__none == "__none" then