Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrated to Uno 5.1 and .NET 8 #9

Draft
wants to merge 40 commits into
base: uno
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
f14b7b2
Implemented basic navigation
Jan 30, 2021
c2a3c92
Implemented passing initial parameter
xperiandri Feb 21, 2021
f747831
Implemented validation errors as observable collections of objects
xperiandri May 16, 2021
067a8a9
Implemented updateObservableCollection instead of elmStyleMerge
xperiandri May 16, 2021
00eb540
Renamed Samples.sln
Apr 27, 2021
c276086
Added a workflow that builds a NuGet package and pushes it into MyGet
Apr 15, 2021
453f2f6
Added template implementation for visual studio
May 17, 2021
38dcf25
Fixed ICustomProperty implementation in DynamicCustomProperty
xperiandri Jun 29, 2021
2a49978
Fixed ICustomProperty bindings initialization
xperiandri Jul 8, 2021
222a7fc
Updated SolutionTemplate and workflows
xperiandri Jul 9, 2021
a616a3b
Enabled parallel build
xperiandri Aug 24, 2021
b71db34
Fixed deadlock on WASM
xperiandri Aug 14, 2021
419975d
Migrated core and samples projects to Solution.Build.props and aligne…
xperiandri Aug 21, 2021
e09ae2f
Added trys with Debugger.Break() if exception for PropertyChanged and…
xperiandri Aug 21, 2021
db6a613
Fixed SubModelSeq sample containing TreeView by using WinUI version
xperiandri Aug 21, 2021
e379c5a
Added slnf for VSMav and Blend and fixed build on MacOS
xperiandri Sep 24, 2021
574588f
Fixed publishing .editorconfig to template
xperiandri Sep 24, 2021
7fbdc36
Updated to Uno 3.10.*
xperiandri Sep 24, 2021
01421e6
Made all variable GUIDs replaceable on template creation
xperiandri Sep 24, 2021
eef243c
Ordered projects in sln files
xperiandri Oct 16, 2021
e222b47
Updated FSharp.Core to 6.0.* and Microsoft.UI.Xaml to 2.7.*
xperiandri Oct 16, 2021
f5951d5
Improved samples UI with iOS visible bound for each page and title ba…
xperiandri Oct 23, 2021
51820d2
Added Fantomas configuration to .editorconfig
xperiandri Oct 23, 2021
eeb10bd
Set C# and F# language versions and FSharp.Core version via variables
xperiandri Apr 7, 2022
38c5d8b
Migrated to Uno.UI 4.1.*, .NET 6 but not MAUI and NuGet 6
xperiandri Jan 17, 2022
4493f7d
Added missing XML comments file for UWP into NuSpec, updated UWP targ…
xperiandri Jan 17, 2022
98003b8
Added missing XML documentation file generation to UWP
xperiandri Feb 20, 2022
89e9771
Updated to .NET 6.0.200 runtime
xperiandri Feb 21, 2022
6f29ea6
Fixed all the warnings and added all the missing XML docs
xperiandri Feb 21, 2022
c61c2f5
Migrated to .NET 6 MAUI
Feb 20, 2022
aeb3623
Set up central version management of Nuget packages, fixed the "Autho…
Apr 11, 2022
60030d5
Set up central version management of Nuget packages, changed SDK vers…
Apr 18, 2022
523e9aa
fixup! Set up central version management of Nuget packages, fixed the…
xperiandri May 15, 2022
5a1b480
Fixed counter minus symbol
xperiandri Oct 26, 2023
b695d8b
Updated to .NET 6 (draft)
Oct 18, 2022
4c7fcf7
Migrated to Uno WinUI
xperiandri Oct 26, 2023
8785d7c
Migrated the library to Uno 5.1 and .NET 8
xperiandri Mar 28, 2024
ef8464f
fixup! Migrated the library to Uno 5.1 and .NET 8
xperiandri Apr 1, 2024
35993e7
fixup! Migrated the library to Uno 5.1 and .NET 8
xperiandri Apr 1, 2024
eaf0ae9
fixup! Migrated the library to Uno 5.1 and .NET 8
Apr 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed ICustomProperty bindings initialization
  • Loading branch information
xperiandri committed Apr 7, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 2a49978a31b02e38f7fb2d34896bdecce999dde8
71 changes: 41 additions & 30 deletions src/Elmish.Uno.Uwp/ViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Immutable;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
@@ -44,7 +45,18 @@ public DynamicCustomProperty(string name, Func<TTarget, TValue> getter, Action<T

internal class ViewModel<TModel, TMsg> : Uno.ViewModel<TModel, TMsg>, ICustomPropertyProvider
{
public ViewModel(TModel initialModel, FSharpFunc<TMsg, Unit> dispatch, FSharpList<Binding<TModel, TMsg>> bindings, ElmConfig config, string propNameChain) : base(initialModel, dispatch, bindings, config, propNameChain) { }
private readonly ImmutableDictionary<string, string> bindingsMap;

public ViewModel(TModel initialModel, FSharpFunc<TMsg, Unit> dispatch, FSharpList<Binding<TModel, TMsg>> bindings, ElmConfig config, string propNameChain) : base(initialModel, dispatch, bindings, config, propNameChain)
{
string GetBindingType(Binding<TModel, TMsg> binding)
{
//var (info, _) = FSharpValue.GetUnionFields(binding.Data, typeof(BindingData<TModel, TMsg>), FSharpOption<BindingFlags>.Some(BindingFlags.NonPublic));
return binding.Data.GetType().Name;
}

this.bindingsMap = bindings.ToImmutableDictionary(b => b.Name, GetBindingType);
}

public override Uno.ViewModel<object, object> Create(object initialModel, FSharpFunc<object, Unit> dispatch, FSharpList<Binding<object, object>> bindings, ElmConfig config, string propNameChain)
=> new ViewModel<object, object>(initialModel, dispatch, bindings, config, propNameChain);
@@ -53,36 +65,35 @@ private ICustomProperty GetProperty(string name)
{
if (name == "CurrentModel") return new DynamicCustomProperty<ViewModel<TModel, TMsg>, object>(name, vm => vm.CurrentModel);
if (name == "HasErrors") return new DynamicCustomProperty<ViewModel<TModel, TMsg>, bool>(name, vm => ((INotifyDataErrorInfo)vm).HasErrors);
if (!this.Bindings.TryGetValue(name, out var binding)) Debugger.Break();
switch (binding)
if (!bindingsMap.TryGetValue(name, out var bindingType)) Debugger.Break();
switch (bindingType)
{
case VmBinding<TModel, TMsg>.OneWay oneWay:
return new DynamicCustomProperty<ViewModel<TModel, TMsg>, object>(name, vm => vm.TryGetMember(oneWay));
case VmBinding<TModel, TMsg>.OneWayLazy oneWayLazy:
return new DynamicCustomProperty<ViewModel<TModel, TMsg>, object>(name, vm => vm.TryGetMember(oneWayLazy));
case VmBinding<TModel, TMsg>.OneWaySeq oneWaySeq:
case nameof(BindingData<TModel, TMsg>.OneWayData):
case nameof(BindingData<TModel, TMsg>.OneWayLazyData):
return new DynamicCustomProperty<ViewModel<TModel, TMsg>, object>(name, vm => vm.TryGetMember(vm.Bindings[name]));
case nameof(BindingData<TModel, TMsg>.OneWaySeqLazyData):
return new DynamicCustomProperty<ViewModel<TModel, TMsg>, ObservableCollection<object>>(name,
vm => (ObservableCollection<object>)vm.TryGetMember(oneWaySeq));
case VmBinding<TModel, TMsg>.TwoWay twoWay:
return new DynamicCustomProperty<ViewModel<TModel, TMsg>, object>(name, vm => vm.TryGetMember(twoWay), (vm, value) => vm.TrySetMember(value, twoWay));
case VmBinding<TModel, TMsg>.TwoWayValidate twoWayValidate:
return new DynamicCustomProperty<ViewModel<TModel, TMsg>, object>(name, vm => vm.TryGetMember(twoWayValidate), (vm, value) => vm.TrySetMember(value, twoWayValidate));
case VmBinding<TModel, TMsg>.Cmd cmd:
return new DynamicCustomProperty<ViewModel<TModel, TMsg>, ICommand>(name, vm => vm.TryGetMember(cmd) as ICommand);
case VmBinding<TModel, TMsg>.CmdParam cmdParam:
return new DynamicCustomProperty<ViewModel<TModel, TMsg>, object>(name, vm => vm.TryGetMember(cmdParam));
case VmBinding<TModel, TMsg>.SubModel subModel:
vm => (ObservableCollection<object>)vm.TryGetMember(vm.Bindings[name]));
case nameof(BindingData<TModel, TMsg>.TwoWayData):
return new DynamicCustomProperty<ViewModel<TModel, TMsg>, object>(name,
vm => vm.TryGetMember(vm.Bindings[name]), (vm, value) => vm.TrySetMember(value, vm.Bindings[name]));
case nameof(BindingData<TModel, TMsg>.TwoWayValidateData):
return new DynamicCustomProperty<ViewModel<TModel, TMsg>, object>(name,
vm => vm.TryGetMember(vm.Bindings[name]), (vm, value) => vm.TrySetMember(value, vm.Bindings[name]));
case nameof(BindingData<TModel, TMsg>.CmdData):
return new DynamicCustomProperty<ViewModel<TModel, TMsg>, ICommand>(name,
vm => vm.TryGetMember(vm.Bindings[name]) as ICommand);
case nameof(BindingData<TModel, TMsg>.CmdParamData):
return new DynamicCustomProperty<ViewModel<TModel, TMsg>, object>(name, vm => vm.TryGetMember(vm.Bindings[name]));
case nameof(BindingData<TModel, TMsg>.SubModelData):
return new DynamicCustomProperty<ViewModel<TModel, TMsg>, ViewModel<object, object>>(name,
vm => vm.TryGetMember(subModel) as ViewModel<object, object>);
case VmBinding<TModel, TMsg>.SubModelSeq subModelSeq:
vm => vm.TryGetMember(vm.Bindings[name]) as ViewModel<object, object>);
case nameof(BindingData<TModel, TMsg>.SubModelSeqData):
return new DynamicCustomProperty<ViewModel<TModel, TMsg>, ObservableCollection<Uno.ViewModel<object, object>>>(name,
vm => (ObservableCollection<Uno.ViewModel<object, object>>)vm.TryGetMember(subModelSeq));
case VmBinding<TModel, TMsg>.SubModelSelectedItem subModelSelectedItem:
vm => (ObservableCollection<Uno.ViewModel<object, object>>)vm.TryGetMember(vm.Bindings[name]));
case nameof(BindingData<TModel, TMsg>.SubModelSelectedItemData):
return new DynamicCustomProperty<ViewModel<TModel, TMsg>, ViewModel<object, object>>(name,
vm => (ViewModel<object, object>) vm.TryGetMember(subModelSelectedItem));
case VmBinding<TModel, TMsg>.Cached cached:
return new DynamicCustomProperty<ViewModel<TModel, TMsg>, object>(name,
vm => vm.TryGetMember(cached), (vm, value) => vm.TrySetMember(value, cached));
vm => (ViewModel<object, object>)vm.TryGetMember(vm.Bindings[name]));
default:
return null;
//throw new NotSupportedException();
@@ -122,22 +133,22 @@ public static void StartLoop<TModel, TMsg>(ElmConfig config, FrameworkElement el
FSharpRef<FSharpOption<ViewModel<TModel, TMsg>>> lastModel = new FSharpRef<FSharpOption<ViewModel<TModel, TMsg>>>(null);
FSharpFunc<FSharpFunc<TMsg, Unit>, FSharpFunc<TMsg, Unit>> syncDispatch =
FuncConvert.FromAction(MakeSyncDispatch<TMsg>(element));
var setSate = FuncConvert.FromAction(MakeSetState(config, element, program, lastModel));
var setState = FuncConvert.FromAction(MakeSetState(config, element, program, lastModel));
programRun.Invoke(
ProgramModule.withSyncDispatch(syncDispatch,
ProgramModule.withSetState(setSate, program)));
ProgramModule.withSetState(setState, program)));
}

public static void StartLoop<T, TModel, TMsg>(ElmConfig config, FrameworkElement element, Action<T, Program<T, TModel, TMsg, FSharpList<Binding<TModel, TMsg>>>> programRun, Program<T, TModel, TMsg, FSharpList<Binding<TModel, TMsg>>> program, T arg)
{
FSharpRef<FSharpOption<ViewModel<TModel, TMsg>>> lastModel = new FSharpRef<FSharpOption<ViewModel<TModel, TMsg>>>(null);
FSharpFunc<FSharpFunc<TMsg, Unit>, FSharpFunc<TMsg, Unit>> syncDispatch =
FuncConvert.FromAction(MakeSyncDispatch<TMsg>(element));
var setSate = FuncConvert.FromAction(MakeSetState(config, element, program, lastModel));
var setState = FuncConvert.FromAction(MakeSetState(config, element, program, lastModel));

programRun.Invoke(arg,
ProgramModule.withSyncDispatch(syncDispatch,
ProgramModule.withSetState(setSate, program)));
ProgramModule.withSetState(setState, program)));
}