From 50803d46a87b88e36a9031f45f2142396dce3704 Mon Sep 17 00:00:00 2001 From: Gibran Rosa Date: Thu, 17 May 2018 10:26:57 -0300 Subject: [PATCH] Fix #45 : Modified Generator to Reference Properties updates NOT UpdateIncremental when types of Old and New object differs --- Elmish.XamarinForms/DynamicXaml.fs | 24 ++++++++++++++++-------- Generator/Program.cs | 5 +++-- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/Elmish.XamarinForms/DynamicXaml.fs b/Elmish.XamarinForms/DynamicXaml.fs index 824748b8a..773a8e08d 100644 --- a/Elmish.XamarinForms/DynamicXaml.fs +++ b/Elmish.XamarinForms/DynamicXaml.fs @@ -3588,8 +3588,9 @@ type Xaml() = match prevChildOpt, source.TryContent with // For structured objects, dependsOn on reference equality | USome prevChild, USome newChild when System.Object.ReferenceEquals(prevChild, newChild) -> () - | USome prevChild, USome newChild -> + | USome prevChild, USome newChild when prevChild.TargetType = newChild.TargetType -> newChild.UpdateIncremental(prevChild, target.Content) + | USome _, USome newChild | UNone, USome newChild -> target.Content <- newChild.CreateAsView() | USome _, UNone -> @@ -6215,8 +6216,9 @@ type Xaml() = match prevChildOpt, source.TryContent with // For structured objects, dependsOn on reference equality | USome prevChild, USome newChild when System.Object.ReferenceEquals(prevChild, newChild) -> () - | USome prevChild, USome newChild -> + | USome prevChild, USome newChild when prevChild.TargetType = newChild.TargetType -> newChild.UpdateIncremental(prevChild, target.Content) + | USome _, USome newChild | UNone, USome newChild -> target.Content <- newChild.CreateAsView() | USome _, UNone -> @@ -7175,8 +7177,9 @@ type Xaml() = match prevChildOpt, source.TryContent with // For structured objects, dependsOn on reference equality | USome prevChild, USome newChild when System.Object.ReferenceEquals(prevChild, newChild) -> () - | USome prevChild, USome newChild -> + | USome prevChild, USome newChild when prevChild.TargetType = newChild.TargetType -> newChild.UpdateIncremental(prevChild, target.Content) + | USome _, USome newChild | UNone, USome newChild -> target.Content <- newChild.CreateAsView() | USome _, UNone -> @@ -9966,8 +9969,9 @@ type Xaml() = match prevChildOpt, source.TryCurrentPage with // For structured objects, dependsOn on reference equality | USome prevChild, USome newChild when System.Object.ReferenceEquals(prevChild, newChild) -> () - | USome prevChild, USome newChild -> + | USome prevChild, USome newChild when prevChild.TargetType = newChild.TargetType -> newChild.UpdateIncremental(prevChild, target.CurrentPage) + | USome _, USome newChild | UNone, USome newChild -> target.CurrentPage <- newChild.CreateAsContentPage() | USome _, UNone -> @@ -10653,8 +10657,9 @@ type Xaml() = match prevChildOpt, source.TryContent with // For structured objects, dependsOn on reference equality | USome prevChild, USome newChild when System.Object.ReferenceEquals(prevChild, newChild) -> () - | USome prevChild, USome newChild -> + | USome prevChild, USome newChild when prevChild.TargetType = newChild.TargetType -> newChild.UpdateIncremental(prevChild, target.Content) + | USome _, USome newChild | UNone, USome newChild -> target.Content <- newChild.CreateAsView() | USome _, UNone -> @@ -10864,8 +10869,9 @@ type Xaml() = match prevChildOpt, source.TryMaster with // For structured objects, dependsOn on reference equality | USome prevChild, USome newChild when System.Object.ReferenceEquals(prevChild, newChild) -> () - | USome prevChild, USome newChild -> + | USome prevChild, USome newChild when prevChild.TargetType = newChild.TargetType -> newChild.UpdateIncremental(prevChild, target.Master) + | USome _, USome newChild | UNone, USome newChild -> target.Master <- newChild.CreateAsPage() | USome _, UNone -> @@ -10875,8 +10881,9 @@ type Xaml() = match prevChildOpt, source.TryDetail with // For structured objects, dependsOn on reference equality | USome prevChild, USome newChild when System.Object.ReferenceEquals(prevChild, newChild) -> () - | USome prevChild, USome newChild -> + | USome prevChild, USome newChild when prevChild.TargetType = newChild.TargetType -> newChild.UpdateIncremental(prevChild, target.Detail) + | USome _, USome newChild | UNone, USome newChild -> target.Detail <- newChild.CreateAsPage() | USome _, UNone -> @@ -11321,8 +11328,9 @@ type Xaml() = match prevChildOpt, source.TryView with // For structured objects, dependsOn on reference equality | USome prevChild, USome newChild when System.Object.ReferenceEquals(prevChild, newChild) -> () - | USome prevChild, USome newChild -> + | USome prevChild, USome newChild when prevChild.TargetType = newChild.TargetType -> newChild.UpdateIncremental(prevChild, target.View) + | USome _, USome newChild | UNone, USome newChild -> target.View <- newChild.CreateAsView() | USome _, UNone -> diff --git a/Generator/Program.cs b/Generator/Program.cs index fb9b7646e..4f33a3b3a 100644 --- a/Generator/Program.cs +++ b/Generator/Program.cs @@ -199,7 +199,7 @@ static int Main(string[] args) try { if (args.Length < 2) { - Console.Error.WriteLine("usage: generator "); + Console.Error.WriteLine("usage: generator "); Environment.Exit(1); } var bindingsPath = args[0]; @@ -497,8 +497,9 @@ static string BindTypes (Bindings bindings) w.WriteLine($" match prevChildOpt, source.Try{m.BoundUniqueName} with"); w.WriteLine($" // For structured objects, dependsOn on reference equality"); w.WriteLine($" | USome prevChild, USome newChild when System.Object.ReferenceEquals(prevChild, newChild) -> ()"); - w.WriteLine($" | USome prevChild, USome newChild ->"); + w.WriteLine($" | USome prevChild, USome newChild when prevChild.TargetType = newChild.TargetType ->"); w.WriteLine($" newChild.UpdateIncremental(prevChild, target.{m.Name})"); + w.WriteLine($" | USome _, USome newChild"); w.WriteLine($" | UNone, USome newChild ->"); w.WriteLine($" target.{m.Name} <- newChild.CreateAs{bt.Name}()"); w.WriteLine($" | USome _, UNone ->");