Skip to content

Instantly share code, notes, and snippets.

@jsonberry
Last active January 14, 2019 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsonberry/b067ad939e9c1e3b383fc8e2c48b9bd0 to your computer and use it in GitHub Desktop.
Save jsonberry/b067ad939e9c1e3b383fc8e2c48b9bd0 to your computer and use it in GitHub Desktop.
rxjs-examples
import { someDataSource } from './some-api.service';
import { ignoreFalsySignals, tapLog } from 'rxjs-toolkit';
interface Signal {
foo: string;
}
/**
* signals$ pushes out an Observable of Signal
* imagine the source of the stream is the return from an API call
* when the stream first connects via the subscription
* the signal value could be undefined
*/
someDataSource.signals$.pipe(
/**
* this does not cut the stream off
* instead, it will only let truthy values through
* once a JSON payload from an API request arrives
* the data will flow through into the next callback of the Subscription
*/
tapLog(), // undefined, { foo: 'hello rxjs world' }
ignoreFalsySignals(),
tapLog(), // { foo: 'hello rxjs world' }
).subscribe({
next(signal) {
doFooThings(signal.foo); // we've guaranteed that the signal is not undefined
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment