This is a conceptual problem with reactive programming due to my misunderstanding, I think.
I have an Observable
that issues a network call returning JSON, which I filter()
, looking at the JSON for an admin flag, and then perform actions in the subscribe()
method.
observable
.filter((json) -> { return json.isAdmin; })
.subscribe((json) -> { /* Do things for admin */ });
I also want to do the same, but when the user is not an admin:
observable
.filter((json) -> { return !json.isAdmin; })
.subscribe((json) -> { /* Do things for non-admin */ });
I am now aware if I run the above two code block, the network call will be twice called.
I know I can put an if statement in a single subscribe()
method, but I'm not sure if this is the reactive way.
Is there a way where I can keep the above structure but only set the observable in motion once--i.e. one network call not two?
It seems as if I want to react in multiple ways to an Observable
's result, without making that Observable run multiple times.