-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from mercari/keithyokoma/feature/no_op_reducer
NoOpReducer for the convenience of having `no state change` reducer
- Loading branch information
Showing
2 changed files
with
43 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.mercari.rxredux | ||
|
||
/** | ||
* This reducer always returns the same state. | ||
*/ | ||
class NoOpReducer<S : State, A : Action> : Reducer<S, A> { | ||
override fun reduce(currentState: S, action: A): S = currentState | ||
} |
35 changes: 35 additions & 0 deletions
35
rxredux/src/test/java/com/mercari/rxredux/NoOpReducerTest.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,35 @@ | ||
package com.mercari.rxredux | ||
|
||
import org.amshove.kluent.shouldEqual | ||
import org.spekframework.spek2.Spek | ||
import org.spekframework.spek2.style.gherkin.Feature | ||
|
||
object NoOpReducerTest : Spek({ | ||
|
||
Feature("NoOpReducer") { | ||
|
||
Scenario("Reducing the state with NoOpReducer") { | ||
|
||
lateinit var reducer: NoOpReducer<TestState, TestAction> | ||
lateinit var state: TestState | ||
lateinit var newState: TestState | ||
|
||
Given("Initialize NoOpReducer") { | ||
reducer = NoOpReducer() | ||
state = TestState() | ||
} | ||
|
||
When("Reduce the action") { | ||
newState = reducer.reduce(state, TestAction) | ||
} | ||
|
||
Then("No state changes will happen") { | ||
newState shouldEqual state | ||
} | ||
} | ||
} | ||
}) | ||
|
||
data class TestState(val meaningless: String = "meaningless") : State | ||
|
||
object TestAction : Action |