- Clone repository
- Build 'reduxCore' module
- Add @aar file to your project
- Define default state
val defaultState = ""
- Define action
class AddSymbolAction : Action
- Define reducer
class AddSymbolReducer : Reducer<String> {
override fun reduce(oldState: String, action: Action): String =
(action as? AddSymbolReducer)?.let { oldState + "$" } ?: oldState
}
- Create middleware
class LogActionMiddleware : Middleware<String> {
override fun dispatch(state: Observable<String>, action: Action): Observable<String> =
state.doOnNext { Log.d("TAG", action.toString()) }
}
- Create store
val store = Store(
defaultState,
listOf(Observable.just<Action>(AddSymbolAction())),
listOf(AddSymbolReducer()),
listOf(LogActionMiddleware()))
- Call .bind method with scheduler
store
.bind(AndroidSchedulers.mainThread())
.subscribe({ /* render state */ }, { /* handle error */ })