From ab8217568bc1b02407e9936355b9221bddee8ef7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wies=C5=82aw=20S=CC=8Colte=CC=81s?= Date: Tue, 17 Dec 2024 00:51:05 +0100 Subject: [PATCH] Use ReactiveGenerator --- azure-pipelines.yml | 2 +- global.json | 2 +- samples/TestApp/TestApp.csproj | 19 +++++++++- .../TestApp/ViewModels/FileItemViewModel.cs | 23 ++++------- .../TestApp/ViewModels/MainWindowViewModel.cs | 38 ++++++------------- 5 files changed, 39 insertions(+), 45 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 44e6b654..82bd66fc 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -11,7 +11,7 @@ resources: variables: BuildConfiguration: 'Release' BuildPlatform: 'Any CPU' - PublishFramework: 'net8.0' + PublishFramework: 'net9.0' PublishProject: '' PublishRuntime: '' Workloads: 'wasm-tools wasm-experimental' diff --git a/global.json b/global.json index 78656299..6f4a5233 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "8.0.100", + "version": "9.0.100", "rollForward": "latestMinor", "allowPrerelease": true } diff --git a/samples/TestApp/TestApp.csproj b/samples/TestApp/TestApp.csproj index e3b7c8dc..613c2d6b 100644 --- a/samples/TestApp/TestApp.csproj +++ b/samples/TestApp/TestApp.csproj @@ -1,13 +1,23 @@  WinExe - net8.0 + net9.0 False enable true TestApp + + true + $(BaseIntermediateOutputPath)\GeneratedFiles + + + + 13 + true + + @@ -27,4 +37,11 @@ + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + diff --git a/samples/TestApp/ViewModels/FileItemViewModel.cs b/samples/TestApp/ViewModels/FileItemViewModel.cs index dc0eb73e..7ec920fe 100644 --- a/samples/TestApp/ViewModels/FileItemViewModel.cs +++ b/samples/TestApp/ViewModels/FileItemViewModel.cs @@ -6,23 +6,14 @@ namespace TestApp.ViewModels; -public class FileItemViewModel : ViewModelBase +public partial class FileItemViewModel : ViewModelBase { - private string _name; - private string _path; - - public string Name - { - get => _name; - set => this.RaiseAndSetIfChanged(ref _name, value); - } - - public string Path - { - get => _path; - set => this.RaiseAndSetIfChanged(ref _path, value); - } - + [Reactive] + public partial string Name { get; set; } + + [Reactive] + public partial string Path { get; set; } + public ICommand RemoveCommand { get; } public ICommand OpenInExplorerCommand { get; } diff --git a/samples/TestApp/ViewModels/MainWindowViewModel.cs b/samples/TestApp/ViewModels/MainWindowViewModel.cs index 9c7d76c9..aff9d613 100644 --- a/samples/TestApp/ViewModels/MainWindowViewModel.cs +++ b/samples/TestApp/ViewModels/MainWindowViewModel.cs @@ -12,42 +12,28 @@ using Avalonia.Controls; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Platform.Storage; -using Avalonia.Threading; using DynamicData; using DynamicData.Binding; using ReactiveUI; -using Svg.CodeGen.Skia; using Svg.Skia; using TestApp.Models; using TestApp.Services; namespace TestApp.ViewModels; -public class MainWindowViewModel : ViewModelBase +public partial class MainWindowViewModel : ViewModelBase { private readonly ObservableCollection? _items; - private FileItemViewModel? _selectedItem; - private string? _itemQuery; - private ReadOnlyObservableCollection? _filteredItems; - - public FileItemViewModel? SelectedItem - { - get => _selectedItem; - set => this.RaiseAndSetIfChanged(ref _selectedItem, value); - } - - public string? ItemQuery - { - get => _itemQuery; - set => this.RaiseAndSetIfChanged(ref _itemQuery, value); - } - - public ReadOnlyObservableCollection? FilteredItems - { - get => _filteredItems; - set => this.RaiseAndSetIfChanged(ref _filteredItems, value); - } + [Reactive] + public partial FileItemViewModel? SelectedItem { get; set; } + + [Reactive] + public partial string? ItemQuery { get; set; } + + [Reactive] + public partial ReadOnlyObservableCollection? FilteredItems { get; set; } + public ICommand ResetQueryCommand { get; } public ICommand LoadConfigurationCommand { get; } @@ -86,7 +72,7 @@ public MainWindowViewModel() { _items = new ObservableCollection(); - var queryFilter = this.WhenValueChanged(t => t.ItemQuery) + var queryFilter = this.WhenAnyItemQuery() .Throttle(TimeSpan.FromMilliseconds(100)) .Select(ItemQueryFilter) .DistinctUntilChanged(); @@ -99,7 +85,7 @@ public MainWindowViewModel() .Bind(out _filteredItems) .AsObservableList(); - var resetQueryCanExecute = this.WhenAnyValue(x => x.ItemQuery) + var resetQueryCanExecute = this.WhenAnyItemQuery() .Select(x => !string.IsNullOrWhiteSpace(x)) .ObserveOn(RxApp.MainThreadScheduler);