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
<!-- Copyright 2020 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 --> | |
val currentWeatherFlow: Flow<String> = | |
dataSource.fetchWeatherFlow() | |
.map { ... } | |
.filter { ... } | |
.dropWhile { ... } | |
.combine { ... } | |
.flowOn(Dispatchers.IO) |
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
<!-- Copyright 2020 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 --> | |
val currentWeatherFlow: LiveData<String> = | |
dataSource.fetchWeatherFlow() | |
.map { heavyTransformation(it) } | |
.asLiveData() |
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
<!-- Copyright 2020 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 --> | |
val currentWeatherLiveData: LiveData<String> = | |
dataSource.fetchWeather().switchMap { | |
liveData { emit(heavyTransformation(it)) } | |
} |
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
<!-- Copyright 2020 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 --> | |
val currentWeatherFlow: LiveData<String> = | |
dataSource.fetchWeatherFlow() | |
.onStart { emit(LOADING_STRING) } | |
.asLiveData() |
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
<!-- Copyright 2020 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 --> | |
// Don't use this | |
val currentWeatherFlow: LiveData<String> = liveData { | |
emit(LOADING_STRING) | |
emitSource( | |
dataSource.fetchWeatherFlow().asLiveData() | |
) | |
} |
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
<!-- Copyright 2020 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 --> | |
val currentWeather: LiveData<String> = liveData { | |
emit(LOADING_STRING) | |
emitSource(dataSource.fetchWeather()) | |
} |
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
<!-- Copyright 2020 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 --> | |
val currentWeatherFlow: LiveData<String> = dataSource.fetchWeatherFlow().asLiveData() |
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
<!-- Copyright 2020 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 --> | |
// Don't use this | |
val currentWeatherFlow: LiveData<String> = liveData { | |
dataSource.fetchWeatherFlow().collect { | |
emit(it) | |
} | |
} |
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
<!-- Copyright 2020 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 --> | |
val currentWeather: LiveData<String> = dataSource.fetchWeather() |
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
<!-- Copyright 2020 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 --> | |
class MyViewModel { | |
val result = liveData { | |
emit(repository.fetchData()) | |
} | |
} |