This file contains 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
package com.qwert2603.myapplication | |
import androidx.annotation.CheckResult | |
import kotlinx.coroutines.delay | |
import kotlinx.coroutines.runBlocking | |
class Storage { | |
suspend fun get(): Result<String> = runCatching { | |
delay(1) |
This file contains 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
import org.koin.core.Koin | |
import org.koin.core.context.startKoin | |
import org.koin.core.module.Module | |
import org.koin.core.qualifier.Qualifier | |
import org.koin.core.qualifier.named | |
import org.koin.dsl.module | |
import org.koin.dsl.onClose | |
import org.koin.ext.getFullName | |
// Based on Koin 3.1.2 |
This file contains 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
inline fun <reified K, reified V> Koin.getMultibinding(): Map<K, V> = | |
get<Multibinding<K, V>>(qualifier = multibindingQualifier<K, V>()).toMap() |
This file contains 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
inline fun <reified K, reified V> Module.intoMultibinding(key: K, value: V) { | |
var multibinding: Multibinding<K, V>? = null | |
single( | |
qualifier = named("${K::class.getFullName()}_${V::class.getFullName()}_$key"), | |
createdAtStart = true, | |
) { | |
multibinding = get(multibindingQualifier<K, V>()) | |
multibinding!![key] = value | |
}.onClose { | |
multibinding?.remove(key) |
This file contains 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
fun main() { | |
val koin = startKoin { | |
val module1 = module { | |
declareMultibinding<String, Int>() | |
intoMultibinding("one", 1) | |
intoMultibinding("two", 2) | |
intoMultibinding("three", 3) | |
declareMultibinding<String, Double>() | |
intoMultibinding("one", 1.0) |
This file contains 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 SomeFragment { | |
private val vm = SomeViewModel() | |
fun onCreate() { | |
val currentValue: Int = vm.flow.value | |
// vm.flow.setValue(4) // compilation error | |
} | |
} |
This file contains 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 SomeViewModel : BaseViewModel() { | |
val flow = createViewModelStateFlow(0) | |
suspend fun load() { | |
flow.setValue(1) | |
delay(1000) | |
flow.setValue(flow.value + 1) | |
} | |
} |
This file contains 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
protected class ViewModelStateFlowImpl<T>(initial: T) : ViewModelStateFlow<T> { | |
val wrapped = MutableStateFlow(initial) | |
override val value: T | |
get() = wrapped.value | |
override val replayCache: List<T> | |
get() = wrapped.replayCache | |
@InternalCoroutinesApi |
This file contains 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
import androidx.lifecycle.ViewModel | |
import kotlinx.coroutines.flow.MutableStateFlow | |
import kotlinx.coroutines.flow.StateFlow | |
sealed class ViewModelStateFlow<T>(stateFlow: StateFlow<T>) : StateFlow<T> by stateFlow | |
private class ViewModelStateFlowImpl<T>( | |
initial: T, | |
val wrapped: MutableStateFlow<T> = MutableStateFlow(initial) | |
) : ViewModelStateFlow<T>(wrapped) |
This file contains 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
import 'package:flutter/material.dart'; | |
import 'package:circular_reveal_animation/circular_reveal_animation.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'CRA Demo', |
NewerOlder