-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Closed
Description
This is of course easy when you do it like this:
Observable<List<T>> oMap = Observable.create(...);
But this gives you no informations about added or removed entries. In effect it forces you to iterate through all entries each time the map was changed. Additionally, if the List<T>
contains Observables
itself, you have no way to unsubscribe from removed elements or react on their removal.
My approach is something like this:
List<T> wrapped = new ArrayList<>();
public void onInit() {
List<Action1<T>> addedEntryObservers = new ArrayList<>();
Observer<T> addedEntries = Observable.create(
observer -> observer.add(t -> observer.onNext(t))
);
}
public void add(T t) {
wrapped.add(t);
addedEntryObservers.forEach(o -> o.call(t));
}
But this requires me to write some strange combinators if I just want to get all entries currently in the list.
Is there a canonical way to do this (yet)?
Metadata
Metadata
Assignees
Labels
No labels