mirror of
https://github.com/littensy/charm.git
synced 2026-10-20 17:51:37 +00:00
fix: apply patches to non-table values
This commit is contained in:
parent
382bc3a904
commit
f2ec300204
1 changed files with 8 additions and 10 deletions
|
|
@ -40,19 +40,17 @@ local function diff(prevState: { [any]: any }, nextState: { [any]: any })
|
|||
return patches
|
||||
end
|
||||
|
||||
local function apply(state: { [any]: any }, patches: { [any]: any })
|
||||
local function apply(state: any, patches: any): any
|
||||
if type(patches) == "table" and patches.__none == "__none" then
|
||||
return nil
|
||||
elseif type(state) ~= "table" or type(patches) ~= "table" then
|
||||
return patches
|
||||
end
|
||||
|
||||
local nextState = table.clone(state)
|
||||
|
||||
for key, patch in patches do
|
||||
local current = nextState[key]
|
||||
|
||||
if type(patch) == "table" and patch.__none == "__none" then
|
||||
nextState[key] = nil
|
||||
elseif type(patch) == "table" and type(current) == "table" then
|
||||
nextState[key] = apply(current, patch)
|
||||
else
|
||||
nextState[key] = patch
|
||||
end
|
||||
nextState[key] = apply(nextState[key], patch)
|
||||
end
|
||||
|
||||
return nextState
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue