Naming Convention for Methods Returning RxJava Completed

I have an Android app with a view class ( Fragment, Activity) watching it ViewModel.

ViewModelprovides methods such as getUserNamewhich returns Observable<String>. Although it may be possible to find a better name (maybe observeUserName), I am pleased with the current one - this is quite explanatory.

However, the tricky part begins here: ViewModelit can also show that the view is performing some operation - for example, closing itself, pop-backstack, etc. In this case, ViewModeldefines the following method (and the corresponding one Subject):

class ViewModel {
   // other methods, fields

   // ViewModel can call returnToPreviousScreen.onComplete()
   CompletableSubject returnToPreviousScreen = CompletableSubject.create();

   Completable returnToPreviousScreen() { return returnToPreviousScreen; }
}

In my opinion, the name of the method is terrible. Hover, I can't find anything better. Something like this observeWhenToReturnToPreviousScreenmay be more explanatory, but difficult to read.

, - , , ?

+6
1

, .


rx-java :

  1. "" ( )?
  2. rx java, subscribe?

, :

{name_of_the_method}.


) getUserName

getUserName.

👎 , getUserName stream. , , , get.

getUserName().subscribe()

) observeUserName

observeUserName observeUserName.

👎 stream , subscribe. Observable observing. , .

observeUserName().subscribe()

C) userNames

userNames.

Might . userName userName subscribe. , , userNames , userName.

userNames().subscribe()

) userNameChanges

userNameChanges.

Method ( "") subscribe.

userNameChanges().subscribe()

returnToPreviousScreen, , - :

returnRequests().

previousScreenRequests().

, :

previousScreenRequest().

( , , Single<Unit> Completable, , ... , , ).

+1

Source: https://habr.com/ru/post/1687864/


All Articles