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

Subscribe to all ReactiveProperty inside a ObservableList? #312

Open
devcube9 opened this issue Feb 19, 2025 · 0 comments
Open

Subscribe to all ReactiveProperty inside a ObservableList? #312

devcube9 opened this issue Feb 19, 2025 · 0 comments

Comments

@devcube9
Copy link

devcube9 commented Feb 19, 2025

Hi

I haven't been able to find a solution for this problem, but I am encountering this frequent enough that I thought it might be a good idea to ask here:

public class Element {
    public ReactiveProperty<bool> Completed = new();
}

public class List {
    public ObservableList<Element> Elements = new();
    public ReadOnlyReactiveProperty<bool> AllCompleted = ???
}

How do I complete AllCompleted here so that it listens to all Element.Completed in Elements list? The main problem is that Elements list is dynamic and can add/remove elements.

In addition, I stumbled upon this observable to convert CollectionChanged to an observable in UniRx here

Observable.FromEvent<NotifyCollectionChangedEventHandler<Element>, NotifyCollectionChangedEventArgs<Element>>(
                h => (sender, e) => h(e),
                h => source.CollectionChanged += h,
                h => source.CollectionChanged -= h);

but I couldn't get it to work in ObservableCollection because of this error:

The type 'NotifyCollectionChangedEventArgs' may not be a ref struct or a type parameter allowing ref structs in order to use it as parameter 'T' in the generic type or method 'Observable.FromEvent<TDelegate, T>(Func<Action, TDelegate>, Action, Action, CancellationToken)'CS9244

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

No branches or pull requests

1 participant