ReactiveProperty icon indicating copy to clipboard operation
ReactiveProperty copied to clipboard

Feature request for ReactiveProperty.R3

Open runceel opened this issue 1 year ago • 16 comments

Please let us know which classes and methods are blockers when migrating from ReactiveProperty to R3.

For Japanese: It’s okay to write in Japanese.(日本語で書いても大丈夫です。)

Candidate features

runceel avatar Jul 14 '24 10:07 runceel

Read-only BindableReactiveProperty class

  • R3.BindableReactiveProperty binds observable property but doesn't have read-only option.
  • R3.ReadOnlyReactiveProperty doesn't bind observable property.
  • I wrote so many lines with Reactive.Bindings.ReadOnlyReactivePropertySlim in WPF xaml files, and I want to keep it to read-only.

Funkest avatar Jul 14 '24 12:07 Funkest

ObservableCollection<TElement>.ObserveElementProperty<TElement, TPropert>() method!!

  • I want to observe INotifyPropertyChanged of elements within the IObservableCollection<T>.
  • This might be related to Cysharp/ObservableCollections rather than R3.
  • I'm not troubled by the absence of ObservableCollection<TElement>.ObserveElementPropertyChanged<TElement>() because I don't use it much in the first place.

hsytkm avatar Jul 14 '24 13:07 hsytkm

@Funkest Thank you for your feature request. At first, this feature would be beneficial if added to R3. So I created an issue for that on R3 repo.

runceel avatar Jul 14 '24 14:07 runceel

@hsytkm I added it to list to implement for ReactiveProperty.R3!

runceel avatar Jul 14 '24 14:07 runceel

@runceel Tx!

Funkest avatar Jul 14 '24 14:07 Funkest

@Funkest neuecc (R3 author) have added IReadOnlyBindableReactiveProperty. Could you check it?

runceel avatar Jul 31 '24 06:07 runceel

It checked working on xaml in WPF. For me frankly, I still hope generic one. I use (ReadOnly)ReactivePropertySlim<T> seamless between domain and UI layers. On domain layer, If it were non-generic, I think it would be quite inconvenient to use.

However, it's sufficient to convert all R3.ReadOnlyReactiveProperty to IBindableReactiveProperty in the ViewModel. Since I don't directly make Binding the domain layer models to XAML, it's not particularly difficult.

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        DataContext = new ViewModel(new SomeDomainModel());
    }

    public class ViewModel
    {
        public IReadOnlyBindableReactiveProperty WordsCount { get; }
        public ReactiveCommand<object> AddRandomWord { get; } = new();

        public ViewModel(ISomeDomainModel someDomainModel)
        {
            WordsCount = someDomainModel.WordsCount.ToReadOnlyBindableReactiveProperty();
            AddRandomWord.Subscribe(_ => someDomainModel.AddWord($"{Random.Shared.Next()}"));
        }
    }

    public class SomeDomainModel : ISomeDomainModel
    {
        readonly List<string> words = [];
        readonly ReactiveProperty<int> wordsCount = new();

        public ReadOnlyReactiveProperty<int> WordsCount => wordsCount.ToReadOnlyReactiveProperty();

        public void AddWord(string word)
        {
            words.Add(word);
            wordsCount.Value++;
        }
    }

    public interface ISomeDomainModel
    {
        ReadOnlyReactiveProperty<int> WordsCount { get; }
        void AddWord(string word);
    }
}

Funkest avatar Jul 31 '24 10:07 Funkest

@runceel fixed a 11th line, sorry. (old shows IBindableReactiveProperty)

Funkest avatar Jul 31 '24 17:07 Funkest

すばらしいプロダクトをご提供いただきありがとうございます!

ObservableCollectionsの内容になりますが、IFilteredReadOnlyObservableCollectionが欲しいです。 こちらのページのとおりISynchronizedViewFilterでフィルタリングができていましたが、ObservableCollections v2.2.0で非GenericsのIListが実装されたため(?)使用できなくなりました。

上記とは関係ない質問ですが、完了したタスクのReactiveCommand.ObserveHasErrors(BindableReactiveProperty.のタイポ?)のように、別ライブラリのクラスにプロパティを追加するのはどうやって実現しているのでしょうか。

Here is a translation from ChatGPT

Thank you for providing such an excellent product!

I would like to have an IFilteredReadOnlyObservableCollection for working with ObservableCollections. Previously, I was able to filter using ISynchronizedViewFilter as described on this page, but it seems that after the implementation of the non-generic IList in ObservableCollections v2.2.0, this functionality is no longer available.

This is an unrelated question, but how do you add properties to classes from another library, like ReactiveCommand.ObserveHasErrors for completed tasks (Is this a typo of BindableReactiveProperty?)?

zerodev1200 avatar Aug 15 '24 05:08 zerodev1200

Ah, the fact that ObservableCollections can no longer be filtered in v2.2.0 is not desirable. I'll try to fix it.

neuecc avatar Aug 15 '24 06:08 neuecc

@neuecc I’m not sure if this is the right place to post this, but I wanted to document what I found.

To retrieve type information of the bound list:

private void Button_Click(object sender, RoutedEventArgs e)
{
    var dg = (FindName("DG") as DataGrid);
    var itemsSource = dg.ItemsSource;
    var collectionViewType = CollectionViewSource.GetDefaultView(itemsSource).GetType();
    Debug.WriteLine($"{collectionViewType}");
}

I haven't been able to debug WPF itself beyond this point, so I’m not entirely sure what’s happening.

My guess is that the INotifyCollectionChangedSynchronizedView<TView>.Count represents the number of items before filtering, which might mean that all the lists are passed when a new ListCollectionView is created.

This is as far as I could figure out. I hope it helps.

zerodev1200 avatar Aug 15 '24 14:08 zerodev1200

@Funkest The generic one was released on R3 v1.2.3.

runceel avatar Aug 26 '24 04:08 runceel

ObservableCollections v3.0.0 reflects filtered collection.

neuecc avatar Sep 03 '24 10:09 neuecc

I have just released a library called R3Utility. Please try using it if you like. (ObservableCollection<TElement>.ObserveElementProperty<TElement, TPropert>() method is not implemented yet)

zerodev1200 avatar Nov 09 '24 16:11 zerodev1200

ObservableCollections.IObservableCollection<T>.ObserveElementProperty() is now supported in R3Utility v0.2.0. Much of the code is referenced in this repository. Thank you.

zerodev1200 avatar Nov 16 '24 06:11 zerodev1200

WPFのEventToXXX シリーズ

runceel avatar Nov 29 '24 11:11 runceel