public override void Visit(PropertyNode node, ControlDiffContext context) { if (!(context.Theirs is PropertyNode theirs)) { return; } var currentControlKind = context.Path.Current; if (TryGetUpdatedCustomPropertyMetadata(currentControlKind, node.Identifier, out var customProperty)) { _deltas.Add(ChangeProperty.GetComponentCustomPropertyChange(context.Path, node.Identifier, node.Expression.Expression, customProperty)); return; } if (node.Expression.Expression != theirs.Expression.Expression) { _deltas.Add(ChangeProperty.GetNormalPropertyChange(context.Path, node.Identifier, node.Expression.Expression)); } }
public override void Visit(BlockNode node, ControlDiffContext context) { if (!(context.Theirs is BlockNode theirs)) { return; } if (node.Name.Kind.TypeName != theirs.Name.Kind.TypeName) { _deltas.Add(new RemoveControl(context.Path, node.Name.Identifier, context.IsInComponent)); _deltas.Add(new AddControl(context.Path, node, GetSubtreeStates(node), context.IsInComponent)); return; } var controlPath = context.Path.Append(node.Name.Identifier); var theirChildrenDict = theirs.Children.ToDictionary(child => child.Name.Identifier); foreach (var child in node.Children) { var childName = child.Name.Identifier; if (theirChildrenDict.TryGetValue(childName, out var theirChild)) { child.Accept(this, new ControlDiffContext(controlPath, theirChild, context.IsInComponent)); theirChildrenDict.Remove(childName); } else { _deltas.Add(new AddControl(controlPath, child, GetSubtreeStates(child), context.IsInComponent)); } } foreach (var kvp in theirChildrenDict) { _deltas.Add(new RemoveControl(controlPath, kvp.Key, context.IsInComponent)); } _childTemplateStore.TryGetTemplate(node.Name.Identifier, out var childTemplate); // Let's handle properties: var theirPropDict = theirs.Properties.ToDictionary(prop => prop.Identifier); foreach (var prop in node.Properties) { var propName = prop.Identifier; if (theirPropDict.TryGetValue(propName, out var theirProp)) { prop.Accept(this, new ControlDiffContext(controlPath, theirProp, context.IsInComponent)); theirPropDict.Remove(propName); } else { // Added property if (childTemplate?.IsComponentTemplate ?? false) { var childCustomProperties = childTemplate.CustomProperties.ToDictionary(c => c.Name); if (childCustomProperties.TryGetValue(prop.Identifier, out var customProp)) { _deltas.Add(ChangeProperty.GetComponentCustomPropertyChange(controlPath, prop.Identifier, prop.Expression.Expression, customProp)); continue; } } _deltas.Add(ChangeProperty.GetNormalPropertyChange(controlPath, prop.Identifier, prop.Expression.Expression)); } } // Removed props foreach (var kvp in theirPropDict) { _deltas.Add(ChangeProperty.GetPropertyRemovedChange(controlPath, kvp.Key)); } // And component functions var theirComponentFunctions = theirs.Functions.ToDictionary(func => func.Identifier); foreach (var func in node.Functions) { var propName = func.Identifier; if (theirComponentFunctions.TryGetValue(propName, out var theirFunc)) { func.Accept(this, new ControlDiffContext(controlPath, theirFunc, context.IsInComponent)); theirComponentFunctions.Remove(propName); } else { if (childTemplate?.IsComponentTemplate ?? false) { var childCustomProperties = childTemplate.CustomProperties.ToDictionary(c => c.Name); if (childCustomProperties.TryGetValue(func.Identifier, out var customProperty)) { _deltas.Add(ChangeComponentFunction.GetFunctionChangeWithMetadata(context.Path, func.Identifier, func, customProperty)); continue; } } } } // Removed functions foreach (var kvp in theirComponentFunctions) { _deltas.Add(ChangeComponentFunction.GetFunctionRemoval(controlPath, kvp.Key)); } }