Created
December 1, 2019 15:56
-
-
Save htdangkhoa/ff43d8d0223bfb874e8e9df58d0ed96a to your computer and use it in GitHub Desktop.
CounterActivity
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
class CounterActivity: AppCompatActivity(), Enhancer<CounterState> { | |
private val store: Store<CounterState> by lazy { | |
Store( | |
CounterReducer(), | |
CounterState() | |
// applyMiddleware(...) | |
) | |
} | |
/** | |
* If you want to see the change history of states, | |
* Kdux has provided us with a tool called KduxDevTools. | |
* We will initialize the store via the composeWithDevTools formula. | |
* | |
* private val store: Store<CounterState> by lazy { | |
* composeWithDevTools( | |
* CounterReducer(), | |
* CounterState() | |
* // applyMiddleware(...) | |
* ) | |
* } | |
*/ | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_counter) | |
btnIncrease.setOnClickListener { | |
CounterAction.increaseAction { store.dispatch(it) } | |
} | |
btnDecrease.setOnClickListener { | |
CounterAction.decreaseAction { store.dispatch(it) } | |
} | |
// btnUndo.setOnClickListener { | |
// store.dispatch(KduxDevToolAction.UNDO) | |
// } | |
// btnRedo.setOnClickListener { | |
// store.dispatch(KduxDevToolAction.REDO) | |
// } | |
// btnReset.setOnClickListener { | |
// store.dispatch(KduxDevToolAction.RESET) | |
// } | |
} | |
override fun onStart() { | |
super.onStart() | |
store.subscribe(this) | |
} | |
override fun onStop() { | |
super.onStop() | |
store.unsubscribe(this) | |
} | |
override fun enhance(state: CounterState) { | |
txtNumber.text = "${state.number}" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment