reactiveui / ReactiveUI.SourceGenerators

Use source generators to generate objects.
MIT License
31 stars 3 forks source link

Support for DynamicData #77

Open martinbu opened 1 month ago

martinbu commented 1 month ago

I already started a discussion here some time ago. https://github.com/reactiveui/ReactiveUI/discussions/3691

The question was if an attribute for DynamicData's .Bind and ReadOnlyObservableCollection could be added too. The original question was asked here: https://github.com/reactivemarbles/DynamicData/issues/348

The reply of @glennawatson was, that this would be something for source generators. Therefore, I want to bring this on the table in this repository.

ChrisPulman commented 1 month ago

I will take a look at what would be required to achieve this My understanding is that you wish to be able to turn this.

private ReadOnlyObservableCollection<Person> _visiblePeople;

ctor()
{
    this.WhenAnyValue(vm => vm.People)
        .Subscribe(people => people
            .ToObservableChangeSet()
            .AutoRefresh(x => x.Deleteed)
            .Filter(x => !x.Deleted)
            .Bind(out _visiblePeople)
            .Subscribe());
}

public ReadOnlyObservableCollection<Person> VisiblePeople => _visiblePeople;

Into this

[BindableDerivedList]
private ReadOnlyObservableCollection<Person> _visiblePeople;

ctor()
{
    this.WhenAnyValue(vm => vm.People)
        .Subscribe(people => people
            .ToObservableChangeSet()
            .AutoRefresh(x => x.Deleteed)
            .Filter(x => !x.Deleted)
            .Bind(out _visiblePeople)
            .Subscribe());
}

Which will then generate

public ReadOnlyObservableCollection<Person> VisiblePeople => _visiblePeople;
martinbu commented 1 month ago

Yes exactly! Thank you for looking into this.