-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a sample of middleware implementation and fixed some issues wit…
…h Koin connection
- Loading branch information
Showing
12 changed files
with
167 additions
and
24 deletions.
There are no files selected for viewing
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
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
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
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
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
7 changes: 7 additions & 0 deletions
7
sample/src/main/java/com/krykun/sample/action/ShowCounterToastAction.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.krykun.sample.action | ||
|
||
import com.krykun.reduxmvi.navigation.action.RequestNavigation | ||
import com.krykun.sample.navigation.MainNavigation | ||
|
||
class ShowCounterToastAction(val counter: Int) : | ||
RequestNavigation(MainNavigation.ShowCounterToast(counter)) |
4 changes: 4 additions & 0 deletions
4
sample/src/main/java/com/krykun/sample/base/BaseNavigationRequest.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.krykun.sample.base | ||
|
||
import com.krykun.reduxmvi.navigation.NavigationRequest | ||
|
15 changes: 15 additions & 0 deletions
15
sample/src/main/java/com/krykun/sample/di/FeatureModule.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.krykun.sample.di | ||
|
||
import com.krykun.sample.middleware.MainMiddleware | ||
import org.koin.core.qualifier.named | ||
import org.koin.dsl.module | ||
|
||
sealed class Feature : com.krykun.reduxmvi.Feature() { | ||
object MAIN : Feature() | ||
} | ||
|
||
val featureModule = arrayOf(module { | ||
factory(named(Feature.MAIN::class.java.simpleName)) { | ||
listOf(get<MainMiddleware>()) | ||
} | ||
}) |
10 changes: 10 additions & 0 deletions
10
sample/src/main/java/com/krykun/sample/di/MiddlewareModule.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.krykun.sample.di | ||
|
||
import com.krykun.sample.middleware.MainMiddleware | ||
import org.koin.dsl.module | ||
|
||
val middlewareModule = arrayOf(module { | ||
factory { | ||
MainMiddleware() | ||
} | ||
}) |
50 changes: 50 additions & 0 deletions
50
sample/src/main/java/com/krykun/sample/middleware/MainMiddleware.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.krykun.sample.middleware | ||
|
||
import com.krykun.reduxmvi.ext.findState | ||
import com.krykun.reduxmvi.global.* | ||
import com.krykun.sample.action.AddCounterAction | ||
import com.krykun.sample.action.ShowCounterToastAction | ||
import com.krykun.sample.presentation.MainState | ||
|
||
class MainMiddleware : Middleware<Action, Store<Action, AppState>> { | ||
|
||
/** | ||
* > When the `AddCounterAction` is dispatched, dispatch a `CounterToastAction` | ||
* | ||
* The `dispatchCounterToastAction` function is defined as follows: | ||
* | ||
* @param action The action that was dispatched. | ||
* @param store The store that the action was dispatched to. | ||
* @param next Dispatcher<Action, Store<Action, AppState>> | ||
* @return The next action | ||
*/ | ||
override fun dispatch( | ||
action: Action, | ||
store: Store<Action, AppState>, | ||
next: Dispatcher<Action, Store<Action, AppState>>, | ||
): Action { | ||
|
||
val next = next.dispatch(action, store) | ||
|
||
when (action) { | ||
is AddCounterAction -> dispatchCounterToastAction(store) | ||
} | ||
|
||
return next | ||
} | ||
|
||
|
||
/** | ||
* "Dispatch a toast action that shows the current counter value." | ||
* | ||
* The function is private because it's only used internally by the MainActivity | ||
* | ||
* @param store Store<Action, AppState> - The store that the middleware is being applied to. | ||
*/ | ||
private fun dispatchCounterToastAction(store: Store<Action, AppState>) { | ||
val counter = store.getState().findState<MainState>().counter | ||
|
||
store.dispatch(ShowCounterToastAction(counter)) | ||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
sample/src/main/java/com/krykun/sample/navigation/MainNavigation.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.krykun.sample.navigation | ||
|
||
import com.krykun.reduxmvi.navigation.NavigationRequest | ||
|
||
sealed class MainNavigation : NavigationRequest { | ||
object EmptyNavEvent : MainNavigation() | ||
data class ShowCounterToast(val counter: Int) : MainNavigation() | ||
} |
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