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
data class Mutation<T : Any>( | |
val mutate: T.() -> T | |
) |
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
interface Mutator<Action : Any, State : Any> { | |
val state: State | |
val accept: (Action) -> Unit | |
} |
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
internal class CalculatorStoreFactory(private val storeFactory: StoreFactory) { | |
fun create(): CalculatorStore = | |
object : CalculatorStore, Store<Intent, State, Nothing> by storeFactory.create( | |
name = "CounterStore", | |
initialState = State(), | |
reducer = ReducerImpl | |
) { | |
} |
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
public static void main(String[] args) { | |
// Let's make a Mobius Loop | |
MobiusLoop<Integer, CounterEvent, CounterEffect> loop = Mobius | |
.loop(new CounterLogic(), new CounterEffectHandler()) | |
.startFrom(0); | |
// And start using our loop | |
loop.dispatchEvent(CounterEvent.INCREMENT); // Model is now 1 | |
loop.dispatchEvent(CounterEvent.DECREMENT); // Model is now 0 | |
loop.dispatchEvent(CounterEvent.DECREMENT); // Sound effect plays! Model is still 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
@Composable | |
fun SomePresenter(events: Flow<EventType>): ModelType { | |
// ... | |
} | |
val models: StateFlow<ModelType> = scope.launchMolecule { | |
SomePresenter(events) | |
} |
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
val udfImplementation: (Flow<Action>) -> Flow<UiState> = ... |
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
lifecycleScope.launch { | |
repoAdapter.loadStateFlow.collect { loadState -> | |
// Show a retry header if there was an error refreshing, and items were previously | |
// cached OR default to the default prepend state | |
header.loadState = loadState.mediator | |
?.refresh | |
?.takeIf { it is LoadState.Error && repoAdapter.itemCount > 0 } | |
?: loadState.prepend | |
val isListEmpty = loadState.refresh is LoadState.NotLoading && repoAdapter.itemCount == 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
override suspend fun load(loadType: LoadType, state: PagingState<Int, Repo>): MediatorResult { | |
val page = when (loadType) { | |
LoadType.REFRESH -> … | |
LoadType.PREPEND -> … | |
LoadType.APPEND -> … | |
} | |
val apiQuery = query + IN_QUALIFIER |
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
override suspend fun initialize(): InitializeAction { | |
return InitializeAction.LAUNCH_INITIAL_REFRESH | |
} |
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
@OptIn(ExperimentalPagingApi::class) | |
class GithubRemoteMediator( | |
… | |
) : RemoteMediator<Int, Repo>() { | |
… | |
} |