diff --git a/RoyalCode.Yasamen/RoyalCode.Yasamen.Forms/FieldBase.cs b/RoyalCode.Yasamen/RoyalCode.Yasamen.Forms/FieldBase.cs index 96b57e3..1bea734 100644 --- a/RoyalCode.Yasamen/RoyalCode.Yasamen.Forms/FieldBase.cs +++ b/RoyalCode.Yasamen/RoyalCode.Yasamen.Forms/FieldBase.cs @@ -346,6 +346,10 @@ public override Task SetParametersAsync(ParameterView parameters) throw new InvalidOperationException( $"{GetType()} does not support changing the {nameof(ModelContext)} dynamically."); } + else + { + changeSupport!.HasCurrentValue(Value); + } if (ModelContext is null) throw new InvalidOperationException( diff --git a/RoyalCode.Yasamen/RoyalCode.Yasamen.Forms/Support/ChangeSupport.cs b/RoyalCode.Yasamen/RoyalCode.Yasamen.Forms/Support/ChangeSupport.cs index 47a84ec..c5571a1 100644 --- a/RoyalCode.Yasamen/RoyalCode.Yasamen.Forms/Support/ChangeSupport.cs +++ b/RoyalCode.Yasamen/RoyalCode.Yasamen.Forms/Support/ChangeSupport.cs @@ -23,6 +23,7 @@ public sealed class ChangeSupport private List? listeners; private bool initialized; private object? initialValue; + private object? currentValue; private bool notifying; internal ChangeSupport(string name, @@ -66,7 +67,7 @@ public ChangeSupportListener OnChanged(PropertyChangedHand throw new ArgumentNullException(nameof(handler)); var listener = new InternalListener(handler); - listeners ??= new(); + listeners ??= []; listeners.Add(listener); var supportListener = new ChangeSupportListener(() => @@ -92,7 +93,7 @@ public ChangeSupportListener OnAnyChanged(AnyPropertyChangedHandler handler) throw new ArgumentNullException(nameof(handler)); var listener = new InternalListener(handler); - listeners ??= new(); + listeners ??= []; listeners.Add(listener); return new ChangeSupportListener(() => @@ -109,7 +110,7 @@ public void Include( var includedChangeSupport = collection.GetChangeSupport(changeSupportName); var include = new IncludeChangeSupport(includedChangeSupport, includedHandler); - includes ??= new(); + includes ??= []; includes.Add(include); } @@ -131,23 +132,21 @@ internal void Initialize(FieldIdentifier identifier, TValue initialValue Identifier = identifier; FieldType = typeof(TValue); this.initialValue = initialValue; + currentValue = initialValue; InitializeIncludes(identifier, initialValue); } - internal void InitializeIncludes(FieldIdentifier identifier, TValue initialValue) + internal void HasCurrentValue(TValue value) { - includes?.ForEach(i => i.Initialize(identifier, initialValue)); - parentPropertyChangeSupport?.GetChangeSupport(Name).InitializeIncludes(identifier, initialValue); + if (Identifier is not null && currentValue is TValue previousValue && !Equals(previousValue, value)) + PropertyHasChanged(Identifier.Value, previousValue, value); } - //TODO: ver se isso é necessário. - internal void SetIdentifier(FieldIdentifier identifier) + internal void InitializeIncludes(FieldIdentifier identifier, TValue initialValue) { - if (!initialized) - throw new InvalidOperationException($"The {nameof(ChangeSupport)} must be initialized"); - - Identifier = identifier; + includes?.ForEach(i => i.Initialize(identifier, initialValue)); + parentPropertyChangeSupport?.GetChangeSupport(Name).InitializeIncludes(identifier, initialValue); } internal void Reset() @@ -156,6 +155,7 @@ internal void Reset() Identifier = default; FieldType = null; initialValue = default; + currentValue = default; includes?.ForEach(i => i.Reset()); @@ -169,6 +169,8 @@ internal void PropertyHasChanged(FieldIdentifier fieldIdentifier, TPr notifying = true; + currentValue = newValue; + listeners?.ForEach(l => { if (l is IPropertyChangeListener typedListener) diff --git a/RoyalCode.Yasamen/RoyalCode.Yasamen.Forms/Support/ChangeSupportCollection.cs b/RoyalCode.Yasamen/RoyalCode.Yasamen.Forms/Support/ChangeSupportCollection.cs index 3e72757..8c11028 100644 --- a/RoyalCode.Yasamen/RoyalCode.Yasamen.Forms/Support/ChangeSupportCollection.cs +++ b/RoyalCode.Yasamen/RoyalCode.Yasamen.Forms/Support/ChangeSupportCollection.cs @@ -7,7 +7,7 @@ namespace RoyalCode.Yasamen.Forms.Support; /// A collection of . /// /// -/// This class manages the and its lifecycle. +/// This class manages the and its life-cycle. /// /// public sealed class ChangeSupportCollection diff --git a/RoyalCode.Yasamen/RoyalCode.Yasamen.Forms/Support/PropertyChangeSupport.cs b/RoyalCode.Yasamen/RoyalCode.Yasamen.Forms/Support/PropertyChangeSupport.cs index 89cc01a..c0bbe59 100644 --- a/RoyalCode.Yasamen/RoyalCode.Yasamen.Forms/Support/PropertyChangeSupport.cs +++ b/RoyalCode.Yasamen/RoyalCode.Yasamen.Forms/Support/PropertyChangeSupport.cs @@ -23,8 +23,8 @@ namespace RoyalCode.Yasamen.Forms.Support; public sealed class PropertyChangeSupport { private readonly ChangeSupportCollection changeSupports; + private readonly PropertyChangeSupport? parent; private Dictionary? properties; - private PropertyChangeSupport? parent; /// /// Creates new without parent. @@ -81,11 +81,12 @@ public void PropertyHasChanged(FieldIdentifier fieldIdentifier, TProp public PropertySupported Property(string name) { - properties ??= new(); + properties ??= []; if (properties.TryGetValue(name, out var obj)) { if (obj is not PropertySupported supported) - throw new InvalidOperationException($"The property with name '{name}' has other type them ('{typeof(TValue).Name}')"); + throw new InvalidOperationException( + $"The property with name '{name}' has other type them ('{typeof(TValue).Name}')"); return supported; } diff --git a/RoyalCode.Yasamen/RoyalCode.Yasamen.Services/Extensions/YasamenDataServiceCollectionExtensions.cs b/RoyalCode.Yasamen/RoyalCode.Yasamen.Services/Extensions/YasamenDataServiceCollectionExtensions.cs index 6424ea0..941d0b1 100644 --- a/RoyalCode.Yasamen/RoyalCode.Yasamen.Services/Extensions/YasamenDataServiceCollectionExtensions.cs +++ b/RoyalCode.Yasamen/RoyalCode.Yasamen.Services/Extensions/YasamenDataServiceCollectionExtensions.cs @@ -13,6 +13,5 @@ public static void AddDataServices(this IServiceCollection services) { services.AddScoped(); services.AddScoped(typeof(FinderPerformerService<,>)); - } } \ No newline at end of file diff --git a/RoyalCode.Yasamen/version.targets b/RoyalCode.Yasamen/version.targets index 49d7fda..5825300 100644 --- a/RoyalCode.Yasamen/version.targets +++ b/RoyalCode.Yasamen/version.targets @@ -4,9 +4,9 @@ net8.0 - 0.1.3.3 - 0.1.3.3 - 0.1.3.3 + 0.1.3.4 + 0.1.3.4 + 0.1.3.4