I'm a freshman in the RxSwift's world.Here is my circumstance: First of all,I have an Enum defines two states of my business. Then,I have 2 buttons,Tap button A, first I want to change the value of Enum to stateA, then send a request. Tap button B will change the value of Enum to stateB, and will send a different request. I would like to use with RxSwift.Appreciate your help.
Asked
Active
Viewed 21 times
1 Answers
0
So you have two causes:
- User taps button A
- User taps button B
And you have three effects:
- Send request A
- Send request B
- Update state enum
That means you will have three Observable chains... Leading from a cause or causes to an effect.
buttonA.rx.tap
.bind(onNext: {
api.sendRequestA()
})
buttonB.rx.tap
.bind(onNext: {
api.sendRequestB()
})
let state = Observable.merge(
buttonA.rx.tap.map { Enum.a },
buttonB.rx.tap.map { Enum.b }
)

Daniel T.
- 32,821
- 6
- 50
- 72
-
Hi,Daniel!Thank you for your help.In your pseudocode I see you separate it into two steps:Sending request and altering state.But Is there a way to make the two step in a chain?Which means when user taps ButtonA/ButtonB, we modify the state firstly, then some observable(s) is observing the state, once the state modified, send a request based on the current state automatically.Thank you very much. – Frank8888 May 22 '23 at 01:40
-
There's no need to do that, and doing so would break Separation of Concerns. Don't break Separation of Concerns. – Daniel T. May 22 '23 at 17:26