Answer the question
In order to leave comments, you need to log in
Can Subjects be used to propagate model changes?
I am developing a fairly heavy, highly loaded application for android. Eats a lot of memory, processes a fairly large amount of data. Development has been going on for more than two years, the architecture has changed more than once during this time, as a result, they came to a combination of flux and rxjava.
In the standard description of flux, nothing is said about multithreading (because it was invented for the web), however, all actions are processed in a separate thread (data thread). This allows you to avoid all sorts of ConcurrentModificationException and so on, especially since some actions are quite heavy and the ui stream simply won't pull. Accordingly, when a view receives dataChanged, it needs to receive data from some store. Since the work with the model is carried out in the data thread, it is simplystore.findSomeEnitityById(id)
can't be done. Instead, you need
store.findSomeEnitityByIdObservable(id).observeOn(AndroidSchedulers.mainThread()).subscribe(...)
BehaviorSubject<EntityList> entities = BehaviorSubject.create();
//Метод в сторе
Observable<Entity> findEntityById(long id, long milliseconds) {
return
entities.throttleLast(milliseconds, TimeUnits.MILLISECONDS).map(entities -> entities.findById(id));
}
//Вьюшка
void onResume() {
subscription = store.findEntityById(id, 1000).observeOn(AndroidSchedulers.mainThread()).subscrive(...);
}
void onPause() {
subscription.unsubscribe();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question