rxjs-skip-empty
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

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>
);

Readme

Keywords

none

Package Sidebar

Install

npm i rxjs-skip-empty

Weekly Downloads

0

Version

1.0.0

License

WTFPL

Unpacked Size

6.21 kB

Total Files

8

Last publish

Collaborators

  • nixxquality