Skip to content

Commit

Permalink
Merge pull request #24 from mercari/keithyokoma/feature/no_op_reducer
Browse files Browse the repository at this point in the history
NoOpReducer for the convenience of having `no state change` reducer
  • Loading branch information
yhanada authored Feb 5, 2020
2 parents 71ec03e + 930c0a7 commit f653266
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
8 changes: 8 additions & 0 deletions rxredux/src/main/java/com/mercari/rxredux/NoOpReducer.kt
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 rxredux/src/test/java/com/mercari/rxredux/NoOpReducerTest.kt
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

0 comments on commit f653266

Please sign in to comment.