Skip to content

Instantly share code, notes, and snippets.

@jsonberry
Last active January 14, 2019 16:58
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/b754677814838376fb47692e86e24426 to your computer and use it in GitHub Desktop.
Save jsonberry/b754677814838376fb47692e86e24426 to your computer and use it in GitHub Desktop.
rxjs-toolkit examples
import { from } from 'rxjs';
import { propsAreTruthy, tapLog } from 'rxjs-toolkit';
const topLevelTruthy = {
one: 'I',
two: 'am',
three: 'truthy',
iHaveNestedProps: { // top level also truthy
nested: null,
},
};
const oneFalsyProp = {
one: 'I',
am: '',
three: 'falsy',
};
from([
topLevelTruthy,
oneFalsyProp,
]).pipe(
propsAreTruthy(),
/**
* by default, all top level properties are checked for truthiness
* the first signal will come through as is
* all of it's top level props are truthy (one, two, three, iHaveNested)
* the next signal has a falsy prop, 'am', it's an empty string
* that signal will get mapped to false
*/
tapLog(),
/**
* { one: 'I', two: 'am', three: 'truthy' iHaveNestedProps: { nested: null } }
* false
*/
).subscribe();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment