Closed weituotian closed 7 years ago
This type of question is better asked on StackOverflow.
@akarnokd
i improve the code style below, is that rxjava Recommend?
but i have not test yet
historyVideoDaoRx.insert(historyVideo)
.flatMap(new Func1<HistoryVideo, Observable<Long>>() {
@Override
public Observable<Long> call(HistoryVideo historyVideo) {
return historyVideoDaoRx.count();
}
})
.flatMap(new Func1<Long, Observable<List<HistoryVideo>>>() {
@Override
public Observable<List<HistoryVideo>> call(Long aLong) {
if (aLong > 60) {
return query.rx().list();
}
return Observable.never();
}
})
.flatMap(new Func1<List<HistoryVideo>, Observable<Void>>() {
@Override
public Observable<Void> call(List<HistoryVideo> historyVideos) {
return historyVideoDaoRx.deleteInTx(historyVideos);
}
})
.subscribe(new Action1<Void>() {
@Override
public void call(Void aVoid) {
}
});
Unless you contribute to RxJava itself, you are bound to the style of your development group/company. Usually it's not a beauty contest and what matters is that the code works or not and you don't commit any of the coding sins (such as subscribing to an Observable from within onNext and such).
@akarnokd ok ! my code work well. but i really not understand how to make it beauty
i am using greendao with rxjava, i am confused about how to implement the code style of rxjava.
you can see the Code nesting below.
the code above mean that when i insert an history by dao object , the i check the total count in table haven more than 60 if does , i will delete 10 in table for that , i must also to query the last 10 in table and then delete the 10 in table. the insert, count , query, delete operation all are rx!
i can not make it beautiful more! how can i acheieve the goal to implement the code style of rxjava?