Last active
January 14, 2019 17:01
-
-
Save jsonberry/b067ad939e9c1e3b383fc8e2c48b9bd0 to your computer and use it in GitHub Desktop.
rxjs-examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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