Skip to content

Instantly share code, notes, and snippets.

@jsonberry
Last active January 9, 2019 03:39
Show Gist options
  • Save jsonberry/f5a3214e1e6e2e27cc9db13b5882c819 to your computer and use it in GitHub Desktop.
Save jsonberry/f5a3214e1e6e2e27cc9db13b5882c819 to your computer and use it in GitHub Desktop.
rxjs-toolkit examples
import { someApiService } from './some-api.service';
import { propsAreTruthy, ignoreFalsySignals } from 'rxjs-toolkit';
// imagine getSource$ return an object like this:
const exampleSource = {
id: '123',
origin: {
name: '',
url: 'noop.com',
}
}
// say we only want a Source signal to come through if the name is truthy
someApiService.getSource$.pipe(
// first check for this prop, if it is falsy, map to false
propsAreTruthy('origin.name'),
// if the origin name is falsy, we'll ignore the signal entirely
// but this still keeps the stream open for the next potential signal to come through
ignoreFalsySignals(),
).subscribe(signal => this.doSourceThings(signal));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment