Skip to content

Instantly share code, notes, and snippets.

@SeongUgJung
Last active August 6, 2019 16:46
Show Gist options
  • Save SeongUgJung/880cdd6d72f0c4fc45b10a6370c701ce to your computer and use it in GitHub Desktop.
Save SeongUgJung/880cdd6d72f0c4fc45b10a6370c701ce to your computer and use it in GitHub Desktop.
// 기존
lifecycleController.addObserver(onInit { Observable.create().subscribe() })
// 코드 추가
interface LifecycleDelegate { operator fun LifecycleObserver.unaryPlus() }
class LifecycleController : LifecycleDelegate {
fun LifecycleObserver.unaryPlus() {
[email protected] += this
}
}
// 변경 후
+onInit { Observable.create().subscribe() }
// 실제 모습
class MainViewModel(delegate: LifecycleDelegate) : LifecycleDelegate by delegate {
init {
+onInit { Observable.create().subscribe() }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment