This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 기존 | |
lifecycleController.addObserver(onInit { Observable.create().subscribe() }) | |
// 코드 추가 | |
interface LifecycleDelegate { operator fun LifecycleObserver.unaryPlus() } | |
class LifecycleController : LifecycleDelegate { | |
fun LifecycleObserver.unaryPlus() { | |
[email protected] += this | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 기존 | |
RxLifecycle().apply { init = Observable.create().subscribe() } | |
// 코드 추가 | |
fun onInit(disposableFunction: () -> disposable): RxLifecycle | |
class RxLifecycle : LifecycleObserver { | |
fun init(init: DisposableFunction): RxLifecycle { | |
this.onInit = init |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity : Activity() { | |
private val lifecycleController = LifecycleController() | |
fun onCreated() { | |
MainViewModel(controller) | |
} | |
} | |
// Controller 는 Activity 에서 주입됩니다. | |
class MainViewModel(private val controller : LifecycleController) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typealias DisposableFunction = () -> Disposable // e.g) Observable.just().subscrbie() | |
class RxLifecycle : LifecycleObserver { | |
private var onInit: DisposableFunction? = null | |
private var initDisposable: Disposable? = null | |
override fun onInit() { | |
// create 시점에 Stream 실행 | |
initDisposable = this.onInit?.invoke() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// lifecycle observers manager | |
class LifecycleController { | |
private val observers = mutableListOf<LifecycleObserver>() | |
private var state: LifecycleState = Unknown | |
fun onInit() { | |
observers.forEach { it.onInit() } | |
state = Init | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Observable.interval(100) // every 100 ms | |
.flatMap { api.data() } // network request | |
.compose(until(PAUSE)) // dispose when onPause | |
.subscribe() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Model | |
data class TitleState(var title: String) | |
@Compose | |
fun Text() { | |
val title = TitleState("hello") | |
+state { title } | |
Text(text=title.text) | |
updateAfter10Seconds { title.title = "hello2" } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface RxBinder { | |
fun bindUntil(event: LifecycleEvent) | |
fun apply(event: LifecycleEvent) | |
} | |
class RxBinderImpl { | |
private val subject = BehaviorSubject.<LifecycleEvent>create() | |
private val disposables = mapOf<LifecycleEvent, MutableList<() -> Disposable>>() | |
override fun bindUntil(event: LifecycleEvent, disposable: () -> Disposable) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BaseLifecycleActivity : Activity { | |
private val lifecycleOwner : LifecycleOwner = LifecycleOwner() | |
fun onCreate() { | |
super.onCreate() | |
notifyEvent(LifecycleEvent.ON_CREATED) | |
} | |
fun onStart() { | |
super.onStart() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SecondAppStarterUsecase(private val context: Context) { | |
fun showSecond(index : Int) { | |
context.startActivity(Intent().apply { putExtra("INDEX",index) }) | |
} | |
} |