From 3f8b178f88081b48f94710e58e1763a55e1878f8 Mon Sep 17 00:00:00 2001 From: Lucien Greathouse Date: Thu, 14 Nov 2019 18:18:38 -0800 Subject: [PATCH] Add support for computing property and name changes in hydration patch computation --- plugin/src/Reconciler.lua | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/plugin/src/Reconciler.lua b/plugin/src/Reconciler.lua index 66762e0d..456ed2aa 100644 --- a/plugin/src/Reconciler.lua +++ b/plugin/src/Reconciler.lua @@ -9,6 +9,7 @@ local t = require(script.Parent.Parent.t) local InstanceMap = require(script.Parent.InstanceMap) local Types = require(script.Parent.Types) local invariant = require(script.Parent.invariant) +local getCanonicalProperty = require(script.Parent.getCanonicalProperty) local setCanonicalProperty = require(script.Parent.setCanonicalProperty) --[[ @@ -287,8 +288,36 @@ function Reconciler:__hydrateInternal(apiInstances, id, instance, hydratePatch) end end - -- TODO: Measure differences in properties and add them to - -- hydratePatch.updates + local changedName = nil + local changedProperties = {} + + if apiInstance.Name ~= instance.Name then + changedName = apiInstance.Name + end + + for propertyName, virtualValue in pairs(apiInstance.Properties) do + local success, existingValue = getCanonicalProperty(instance, propertyName) + + if success then + local decodedValue = self:__decodeApiValue(virtualValue) + + if existingValue ~= decodedValue then + changedProperties[propertyName] = virtualValue + end + end + end + + -- If any properties differed from the virtual instance we read, add it to + -- the hydrate patch so that we can catch up. + if changedName ~= nil or next(changedProperties) ~= nil then + table.insert(hydratePatch.updated, { + id = id, + changedName = changedName, + changedClassName = nil, + changedProperties = changedProperties, + changedMetadata = nil, + }) + end local existingChildren = instance:GetChildren()