advancedose.blogg.se

Kotlin map not null
Kotlin map not null











kotlin map not null

So, the userLiveData emits User(2, "John"). When the setUserId method is called with userId = "2", the value of the userIdLiveData changes and automatically triggers a request for getting the user with id The userLiveData gets automatically notified and will emit User(1, "Sarah"). When the user in the repository gets updated to User(1, "Sarah"), That will return a LiveData containing the value User(1, "Jane"). UserIdLiveData value is set to "1", the switchMap will call getUser(1),

kotlin map not null

In a scenario where the repository contains User(1, "Jane") and User(2, "John"), when the The userIdLiveData is the trigger and the LiveData returned by the repository.getUserById is the "backing" LiveData. Id, from a repository that also returns a LiveData. User id emitted, you want to trigger a request to get the user object corresponding to that The given function func will be executed on the main thread.Ĭonsider the case where you have a LiveData containing a user id. If the given function returns null, then swLiveData is not "backed" by any other "Backing" LiveData means, that all events emitted by it will retransmitted Trigger LiveData and sets resulting LiveData as a "backing" LiveDataĪdded in version 1.0.0 LiveData switchMap ( LiveData trigger, It reacts on changes of trigger LiveData, applies the given function to new value of SwitchMap( LiveData trigger, Function> func)Ĭreates a LiveData, let's name it swLiveData, which follows next flow:

kotlin map not null

LiveData and returns LiveData, which emits resulting values. Passed down without requiring additional explicit calls or dependencies.Īpplies the given function on the main thread to each value emitted by source Transformations aren't calculated unless an observer is observing the returned LiveData object.īecause the transformations are calculated lazily, lifecycle-related behavior is implicitly You can use transformation methods to carry information across the observer's lifecycle. They have been superseded by the correspondingĪndroidx.* packages. The android.arch Architecture Components packages are no longer maintained.













Kotlin map not null