From f2ec3002044c1c5e25a757e71486dfe57eaf78bf Mon Sep 17 00:00:00 2001 From: Richard Date: Wed, 27 Mar 2024 23:49:50 -0700 Subject: [PATCH] fix: apply patches to non-table values --- src/sync/patch.luau | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/sync/patch.luau b/src/sync/patch.luau index df2eda5..661877e 100644 --- a/src/sync/patch.luau +++ b/src/sync/patch.luau @@ -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