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

Feature request for ReactiveProperty.R3 #487

Open
4 tasks
runceel opened this issue Jul 14, 2024 · 16 comments
Open
4 tasks

Feature request for ReactiveProperty.R3 #487

runceel opened this issue Jul 14, 2024 · 16 comments
Assignees

Comments

@runceel
Copy link
Owner

runceel commented Jul 14, 2024

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

@Funkest
Copy link

Funkest commented Jul 14, 2024

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.

@hsytkm
Copy link

hsytkm commented Jul 14, 2024

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.

@runceel
Copy link
Owner Author

runceel commented Jul 14, 2024

@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
Copy link
Owner Author

runceel commented Jul 14, 2024

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

@Funkest
Copy link

Funkest commented Jul 14, 2024

@runceel Tx!

@runceel
Copy link
Owner Author

runceel commented Jul 31, 2024

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

@Funkest
Copy link

Funkest commented Jul 31, 2024

It checked working on xaml in WPF.
For me frankly, I still hope generic one.
I use (ReadOnly)ReactivePropertySlim 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
Copy link

Funkest commented Jul 31, 2024

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

@zerodev1200
Copy link

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

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?)?

@neuecc
Copy link
Collaborator

neuecc commented Aug 15, 2024

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

@zerodev1200
Copy link

@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.

@runceel
Copy link
Owner Author

runceel commented Aug 26, 2024

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

@neuecc
Copy link
Collaborator

neuecc commented Sep 3, 2024

ObservableCollections v3.0.0 reflects filtered collection.

@zerodev1200
Copy link

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
Copy link

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

@runceel
Copy link
Owner Author

runceel commented Nov 29, 2024

WPFのEventToXXX シリーズ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants