diff --git a/lib/src/commonMain/kotlin/org/reduxkotlin/combineEnhancers.kt b/lib/src/commonMain/kotlin/org/reduxkotlin/CombineEnhancers.kt similarity index 100% rename from lib/src/commonMain/kotlin/org/reduxkotlin/combineEnhancers.kt rename to lib/src/commonMain/kotlin/org/reduxkotlin/CombineEnhancers.kt diff --git a/lib/src/commonMain/kotlin/org/reduxkotlin/CombineReducers.kt b/lib/src/commonMain/kotlin/org/reduxkotlin/CombineReducers.kt new file mode 100644 index 0000000..38b0b89 --- /dev/null +++ b/lib/src/commonMain/kotlin/org/reduxkotlin/CombineReducers.kt @@ -0,0 +1,13 @@ +package org.reduxkotlin + +fun combineReducers(vararg reducers: Reducer): Reducer = + { state, action -> + reducers.fold(state, { s, reducer -> reducer(s, action) }) + } + +/** + * combine two reducer with + operator + */ +operator fun Reducer.plus(other: Reducer): Reducer = { s, a -> + other(this(s, a), a) +} \ No newline at end of file diff --git a/lib/src/commonMain/kotlin/org/reduxkotlin/Compose.kt b/lib/src/commonMain/kotlin/org/reduxkotlin/Compose.kt index 9047670..65ca1e0 100644 --- a/lib/src/commonMain/kotlin/org/reduxkotlin/Compose.kt +++ b/lib/src/commonMain/kotlin/org/reduxkotlin/Compose.kt @@ -1,5 +1,8 @@ package org.reduxkotlin +/** + * Composes a list of single argument functions from right to left. + */ fun compose(functions: List<(T) -> T>): (T) -> T = { x -> functions.foldRight(x, { f, composed -> f(composed) }) } diff --git a/lib/src/commonMain/kotlin/org/reduxkotlin/Definitions.kt b/lib/src/commonMain/kotlin/org/reduxkotlin/Definitions.kt index dc39269..4fb32a7 100644 --- a/lib/src/commonMain/kotlin/org/reduxkotlin/Definitions.kt +++ b/lib/src/commonMain/kotlin/org/reduxkotlin/Definitions.kt @@ -12,7 +12,7 @@ typealias StoreSubscription = () -> Unit typealias Dispatcher = (Any) -> Any typealias StoreCreator = (reducer: Reducer, initialState: Any, s: StoreEnhancerWrapper?) -> Store /** - * get a store creator and return a new enhanced one + * Take a store creator and return a new enhanced one * see https://github.com/reactjs/redux/blob/master/docs/Glossary.md#store-enhancer */ typealias StoreEnhancer = (next: StoreCreator) -> StoreCreator @@ -28,7 +28,7 @@ class StoreEnhancerWrapper(val storeEnhancer2: StoreEnhancer) : StoreEnhancer { } /** - * see also https://github.com/reactjs/redux/blob/master/docs/Glossary.md#middleware + * https://github.com/reactjs/redux/blob/master/docs/Glossary.md#middleware */ typealias Middleware = (store: Store) -> (next: Dispatcher) -> (action: Any) -> Any diff --git a/lib/src/commonMain/kotlin/org/reduxkotlin/combineReducers.kt b/lib/src/commonMain/kotlin/org/reduxkotlin/combineReducers.kt deleted file mode 100644 index 98e7da7..0000000 --- a/lib/src/commonMain/kotlin/org/reduxkotlin/combineReducers.kt +++ /dev/null @@ -1,20 +0,0 @@ -package org.reduxkotlin - -fun combineReducers(vararg reducers: Reducer): Reducer = - { state, action -> - reducers.fold(state, { s, reducer -> reducer(s, action) }) - } - -fun Reducer.combinedWith(vararg reducers: Reducer): Reducer { - return { state, action -> - val sAfterFirstReducer = this(state, action) - reducers.fold(sAfterFirstReducer, { s, reducer -> reducer(s, action) }) - } -} - -/** - * combine two reducer with + operator - */ -operator fun Reducer.plus(other: Reducer): Reducer = { s, a -> - other(this(s, a), a) -} \ No newline at end of file