ReSwift/ReSwift
How to subscribe to multiple states separately in one class
Aperta
#318 aperta il 12 gen 2018
Good First Issue
Metriche repository
- Star
- (7603 stelle)
- Metriche merge PR
- (Nessuna PR mergiata in 30 g)
Descrizione
ReSwift Version: 4.0.0
Problem: I have to listen to multiple sub-states separately in one class
Currently, i am doing it like:
class Sample: StoreSubscriber {
init() {
// MARK: Subscriber of state 1, 2
appStore.subscribe(self) { state in
state.select { state in (state.state1, state.state2) }
}
}
// MARK: Listener for state 1, 2
func newState(state: (state1: State1, state2: State2) ) {
// process
}
}
How can i listen to each sub-state separately, so that i can act on only sub-state which get changed??
SomethingLike:
class Sample: StoreSubscriber {
init() {
// MARK: Subscriber
appStore.subscribe(self) { state in
state.select { state in state.state1 }
}
appStore.subscribe(self) { state in
state.select { state in state.state2 }
}
}
// MARK: Listener for state1
func newState(state: State1 ) {
// process
}
// MARK: Listener for state2
func newState(state: State2 ) {
// process
}
}