Skip to content

Commit 10f182b

Browse files
author
Arkadii Ivanov
committed
Get rid of KFunction
1 parent 2773b5f commit 10f182b

File tree

13 files changed

+26
-41
lines changed

13 files changed

+26
-41
lines changed

mvidroid/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ dependencies {
2424
implementation "com.android.support:appcompat-v7:$support_library_version"
2525
implementation 'android.arch.lifecycle:common-java8:1.1.1'
2626
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
27-
api 'com.github.arkivanov:kfunction:1.0.0'
2827
api 'io.reactivex.rxjava2:rxandroid:2.0.2'
2928
api 'com.jakewharton.rxrelay2:rxrelay:2.0.0'
3029
testImplementation 'junit:junit:4.12'

mvidroid/src/main/java/com/arkivanov/mvidroid/component/MviComponent.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.arkivanov.mvidroid.component
22

33
import android.support.annotation.MainThread
4-
import com.arkivanov.kfunction.KConsumer
54
import io.reactivex.disposables.Disposable
65

76
/**
@@ -15,7 +14,7 @@ import io.reactivex.disposables.Disposable
1514
* @param UiEvent type of UI Events
1615
* @param States type of States, typically includes States from all Component's Stores
1716
*/
18-
interface MviComponent<in UiEvent : Any, out States : Any> : KConsumer<UiEvent>, Disposable {
17+
interface MviComponent<in UiEvent : Any, out States : Any> : (UiEvent) -> Unit, Disposable {
1918

2019
/**
2120
* A group of States of Component's Stores. Must be accessed only from Main thread.

mvidroid/src/main/java/com/arkivanov/mvidroid/component/MviStoreBundle.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.arkivanov.mvidroid.component
22

3-
import com.arkivanov.kfunction.KFunction
43
import com.arkivanov.mvidroid.store.MviStore
54

65
/**
@@ -15,7 +14,7 @@ import com.arkivanov.mvidroid.store.MviStore
1514
*/
1615
class MviStoreBundle<Intent : Any, in UiEvent : Any>(
1716
val store: MviStore<*, Intent, *>,
18-
val uiEventTransformer: KFunction<UiEvent, Intent?>? = null,
19-
val labelTransformer: KFunction<Any, Intent?>? = null,
17+
val uiEventTransformer: ((UiEvent) -> Intent?)? = null,
18+
val labelTransformer: ((Any) -> Intent?)? = null,
2019
val isPersistent: Boolean = false
2120
)

mvidroid/src/main/java/com/arkivanov/mvidroid/store/MviDefaultStore.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.arkivanov.mvidroid.store
22

33
import android.support.annotation.MainThread
4-
import com.arkivanov.kfunction.KFunction
54
import com.arkivanov.mvidroid.store.component.MviBootstrapper
65
import com.arkivanov.mvidroid.store.component.MviExecutor
76
import com.arkivanov.mvidroid.store.component.MviReducer
@@ -15,7 +14,7 @@ internal class MviDefaultStore<State : Any, in Intent : Any, Action : Any, out R
1514
@MainThread constructor(
1615
initialState: State,
1716
bootstrapper: MviBootstrapper<Action>? = null,
18-
private val intentToAction: KFunction<Intent, Action>,
17+
private val intentToAction: (Intent) -> Action,
1918
private val executor: MviExecutor<State, Action, Result, Label>,
2019
reducer: MviReducer<State, Result>
2120
) : MviStore<State, Intent, Label> {

mvidroid/src/main/java/com/arkivanov/mvidroid/store/MviStore.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.arkivanov.mvidroid.store
22

33
import android.support.annotation.MainThread
4-
import com.arkivanov.kfunction.KConsumer
54
import io.reactivex.Observable
65
import io.reactivex.disposables.Disposable
76

@@ -14,7 +13,7 @@ import io.reactivex.disposables.Disposable
1413
* @param Intent Type of Intent. Intent is a call to action, it triggers some Action in Store.
1514
* @param Label Type of Label. Labels are used for inter-Store communication.
1615
*/
17-
interface MviStore<State : Any, in Intent : Any, Label : Any> : KConsumer<Intent>, Disposable {
16+
interface MviStore<State : Any, in Intent : Any, Label : Any> : (Intent) -> Unit, Disposable {
1817

1918
/**
2019
* Provides access to current state, must be accessed only from Main thread

mvidroid/src/main/java/com/arkivanov/mvidroid/store/component/MviBootstrapper.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.arkivanov.mvidroid.store.component
22

33
import android.support.annotation.MainThread
4-
import com.arkivanov.kfunction.KConsumer
54
import io.reactivex.disposables.Disposable
65

76
/**
@@ -19,5 +18,5 @@ interface MviBootstrapper<out Action : Any> {
1918
* This Disposable will be managed by Store.
2019
*/
2120
@MainThread
22-
fun bootstrap(dispatch: KConsumer<Action>): Disposable?
21+
fun bootstrap(dispatch: (Action) -> Unit): Disposable?
2322
}

mvidroid/src/main/java/com/arkivanov/mvidroid/store/component/MviExecutor.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.arkivanov.mvidroid.store.component
22

33
import android.support.annotation.MainThread
4-
import com.arkivanov.kfunction.KConsumer
5-
import com.arkivanov.kfunction.KSupplier
64
import io.reactivex.disposables.Disposable
75

86
/**
@@ -13,9 +11,9 @@ import io.reactivex.disposables.Disposable
1311
abstract class MviExecutor<State : Any, in Action : Any, Result : Any, Label : Any> @MainThread constructor() {
1412

1513
private var isInitialized: Boolean = false
16-
private lateinit var stateSupplier: KSupplier<State>
17-
private lateinit var resultConsumer: KConsumer<Result>
18-
private lateinit var labelConsumer: KConsumer<Label>
14+
private lateinit var stateSupplier: () -> State
15+
private lateinit var resultConsumer: (Result) -> Unit
16+
private lateinit var labelConsumer: (Label) -> Unit
1917

2018
/**
2119
* Provides current State of Store, must be accessed only on Main thread
@@ -29,7 +27,7 @@ abstract class MviExecutor<State : Any, in Action : Any, Result : Any, Label : A
2927
* Called internally by Store
3028
*/
3129
@MainThread
32-
fun init(stateSupplier: KSupplier<State>, resultConsumer: KConsumer<Result>, labelConsumer: KConsumer<Label>) {
30+
fun init(stateSupplier: () -> State, resultConsumer: (Result) -> Unit, labelConsumer: (Label) -> Unit) {
3331
if (isInitialized) {
3432
throw IllegalStateException("MviExecutor cannot be reused, please make sure that it is not a singleton")
3533
}

mvidroid/src/main/java/com/arkivanov/mvidroid/store/component/MviSimpleBootstrapper.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
package com.arkivanov.mvidroid.store.component
22

3-
import com.arkivanov.kfunction.KConsumer
43
import io.reactivex.disposables.Disposable
54

65
/**
76
* Simple implementation of [MviBootstrapper] which immediately dispatches the provided Actions one by one
87
*/
98
class MviSimpleBootstrapper<out Action : Any>(private vararg val actions: Action) : MviBootstrapper<Action> {
109

11-
override fun bootstrap(dispatch: KConsumer<Action>): Disposable? {
10+
override fun bootstrap(dispatch: (Action) -> Unit): Disposable? {
1211
actions.forEach(dispatch)
1312
return null
1413
}

mvidroid/src/main/java/com/arkivanov/mvidroid/store/factory/MviDefaultStoreFactory.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.arkivanov.mvidroid.store.factory
22

3-
import com.arkivanov.kfunction.KFunction
43
import com.arkivanov.mvidroid.store.MviDefaultStore
54
import com.arkivanov.mvidroid.store.MviStore
65
import com.arkivanov.mvidroid.store.component.MviBootstrapper
@@ -18,9 +17,9 @@ object MviDefaultStoreFactory : MviStoreFactory {
1817
override fun Nothing.reduce(result: Any): Nothing = this
1918
}
2019

21-
private val NO_OP_INTENT_TO_ACTION: KFunction<Nothing, Any> = { throw UnsupportedOperationException("WTF?") }
20+
private val NO_OP_INTENT_TO_ACTION: (Nothing) -> Any = { throw UnsupportedOperationException("WTF?") }
2221

23-
private val BYPASS_INTENT_TO_ACTION: KFunction<Any, Any> = { it }
22+
private val BYPASS_INTENT_TO_ACTION: (Any) -> Any = { it }
2423

2524
private val BYPASS_EXECUTOR =
2625
object : MviExecutor<Any, Any, Any, Any>() {
@@ -34,10 +33,10 @@ object MviDefaultStoreFactory : MviStoreFactory {
3433
private fun <State : Any, Result : Any> getBypassReducer(): MviReducer<State, Result> = BYPASS_REDUCER as MviReducer<State, Result>
3534

3635
@Suppress("UNCHECKED_CAST")
37-
private fun <Action : Any> getNoOpIntentToAction(): KFunction<Nothing, Action> = NO_OP_INTENT_TO_ACTION as KFunction<Nothing, Action>
36+
private fun <Action : Any> getNoOpIntentToAction(): (Nothing) -> Action = NO_OP_INTENT_TO_ACTION as (Nothing) -> Action
3837

3938
@Suppress("UNCHECKED_CAST")
40-
private fun <Intent : Any> getBypassIntentToAction(): KFunction<Intent, Intent> = BYPASS_INTENT_TO_ACTION as KFunction<Intent, Intent>
39+
private fun <Intent : Any> getBypassIntentToAction(): (Intent) -> Intent = BYPASS_INTENT_TO_ACTION as (Intent) -> Intent
4140

4241
@Suppress("UNCHECKED_CAST")
4342
private fun <State : Any, Intent : Any, Label : Any> getBypassExecutor(): MviExecutor<State, Intent, Intent, Label> =
@@ -46,7 +45,7 @@ object MviDefaultStoreFactory : MviStoreFactory {
4645
override fun <State : Any, Intent : Any, Action : Any, Result : Any, Label : Any> create(
4746
initialState: State,
4847
bootstrapper: MviBootstrapper<Action>?,
49-
intentToAction: KFunction<Intent, Action>,
48+
intentToAction: (Intent) -> Action,
5049
executor: MviExecutor<State, Action, Result, Label>,
5150
reducer: MviReducer<State, Result>?
5251
): MviStore<State, Intent, Label> =

mvidroid/src/main/java/com/arkivanov/mvidroid/store/factory/MviStoreFactory.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.arkivanov.mvidroid.store.factory
22

33
import android.support.annotation.MainThread
4-
import com.arkivanov.kfunction.KFunction
54
import com.arkivanov.mvidroid.store.MviStore
65
import com.arkivanov.mvidroid.store.component.MviBootstrapper
76
import com.arkivanov.mvidroid.store.component.MviExecutor
@@ -33,7 +32,7 @@ interface MviStoreFactory {
3332
fun <State : Any, Intent : Any, Action : Any, Result : Any, Label : Any> create(
3433
initialState: State,
3534
bootstrapper: MviBootstrapper<Action>? = null,
36-
intentToAction: KFunction<Intent, Action>,
35+
intentToAction: (Intent) -> Action,
3736
executor: MviExecutor<State, Action, Result, Label>,
3837
reducer: MviReducer<State, Result>? = null
3938
): MviStore<State, Intent, Label>

0 commit comments

Comments
 (0)