Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. // 기존
  2. lifecycleController.addObserver(onInit { Observable.create().subscribe() })
  3.  
  4. // 코드 추가
  5. interface LifecycleDelegate { operator fun LifecycleObserver.unaryPlus() }
  6. class LifecycleController : LifecycleDelegate {
  7. fun LifecycleObserver.unaryPlus() {
  8. this@LifecycleController.observers += this
  9. }
  10. }
  11.  
  12. // 변경 후
  13. +onInit { Observable.create().subscribe() }
  14.  
  15. // 실제 모습
  16. class MainViewModel(delegate: LifecycleDelegate) : LifecycleDelegate by delegate {
  17. init {
  18. +onInit { Observable.create().subscribe() }
  19. }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement