//reactivestate/com.ensody.reactivestate.android/autoRun
autoRun¶
[android]\ fun ViewModel.autoRun(launcher: CoroutineLauncher = if (this is CoroutineLauncher) this else SimpleCoroutineLauncher(viewModelScope), onChange: AutoRunOnChangeCallback<Unit>? = null, observer: AutoRunCallback<Unit>): AutoRunner<Unit>
Watches observables for changes. Often useful to keep things in sync.
This is a convenience function that immediately starts the AutoRunner.run cycle for you.
Returns the underlying AutoRunner. To stop watching, you should call AutoRunner.dispose. The AutoRunner is automatically disposed when the viewModelScope completes.
See AutoRunner for more details.
Parameters¶
android
onChange | Gets called when the observables change. If you provide a handler you have to manually call run. |
observer | The callback which is used to track the observables. |
[android]\ fun LifecycleOwner.autoRun(launcher: CoroutineLauncher = if (this is CoroutineLauncher) this else LifecycleCoroutineLauncher(this), onChange: AutoRunOnChangeCallback<Unit>? = null, observer: AutoRunCallback<Unit>): AutoRunner<Unit>
Watches observables for changes. Often useful to keep things in sync (e.g. ViewModel -> UI).
This only executes the observer between onStart
/onStop
.
Returns the underlying AutoRunner. To stop watching, you should call AutoRunner.dispose. The AutoRunner is automatically disposed on Activity.onDestroy
/Fragment.onDestroyView
.
See AutoRunner for more details.
Parameters¶
android
onChange | Gets called when the observables change. If you provide a handler you have to manually call run. |
observer | The callback which is used to track the observables. |