All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.com.episode6.redux.api.kt Maven / Gradle / Ivy

The newest version!
package com.episode6.redux

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow

/**
 * Represents a redux store backed by a [kotlinx.coroutines.flow.StateFlow]
 */
interface StoreFlow : Flow {
  val initialState: State
  val state: State
  fun dispatch(action: Action)
}

/**
 * Identifies a redux action that can be dispatched/interpreted by a [StoreFlow]
 */
interface Action

/**
 * Function that dispatches an action to a [StoreFlow]
 */
typealias Dispatch = (Action) -> Unit

/**
 * Reduces a state + action to a new state
 */
typealias Reducer = State.(Action) -> State

/**
 * Gets the chance to interfere with a [StoreFlow]'s dispatch of actions
 */
fun interface Middleware {
  fun CoroutineScope.interfere(store: StoreFlow, next: Dispatch): Dispatch
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy