rxjs-skip-empty
v1.0.0
Published
Filter out null and undefined values in an Observable
Downloads
1
Readme
This is an RXJS operator that simply filters out any null or undefined values.
export const highlightEvent: Epic = (action$, state$) => action$.pipe(
filter(isActionOf(schedule.highlightEventById)),
withLatestFrom(state$),
map(([action, state]) => {
if (!state.schedule.data)
return null;
const { agenda } = state.schedule.data;
if (action.payload === "")
return schedule.setHighlightEvent(undefined);
let event: ScheduleEvent | undefined;
([ 0, 1, 2, 3, 4, 5, 6 ] as const).some(n => {
event = agenda[n].find(e => e.id === action.payload);
return event !== undefined;
});
return schedule.setHighlightEvent(event);
}),
// here it's a Observable<RootAction | null>
skipEmpty(),
// null values are filtered out and the type is Observable<RootAction>
);