Skip to content

Instantly share code, notes, and snippets.

@hughfdjackson
Created June 17, 2015 22:13
Show Gist options
  • Save hughfdjackson/8e56ddca0af059f33b6b to your computer and use it in GitHub Desktop.
Save hughfdjackson/8e56ddca0af059f33b6b to your computer and use it in GitHub Desktop.
A suggested utility function based on RxJS
// Gate takes three Observables.
// gateFlag$: an Observable of booleans
// open$: an Observable of values
// closed$: an Observable of values
var gate = function(gateFlag$, open$, closed$) {
...
};
// Use Case:
// I have an observable of booleans from a checkbox event in the browser.
// Using the `gate` function to combine the streams : `var gated$ = gate(checkbox$, a$, b$)`
// To update the state of gated$, it should apply the following rules:
// When the checkbox *becomes* checked, I want to push the latest result of observable A
// When the checkbox *becomes* unchecked, I want to push the latest result of observable B
// When the checkbox is already checked, and a new value is pushed to observable A, I want to push that value
// When the checkbox is already unchecked, and a new value is pushed to observable B, I want to push that value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment