Grilled Cheese

ExploreLog inSign up
Terms of UsePrivacy PolicyCommunity StandardsHelpGet the app

Grilled Cheese is a product of Village Compute

Version devBuilt at: 2026-12-03 22:42:33 EST

PhotosVideosAllPeople
LatestRanked
?Unknown authorDec 1, 2026, 12:58 PM

Have you ever done this?

#RxJS #Angular #TypeScript #WebDev

search$.pipe(
  debounceTime(300),
  switchMap((query) =>
    this.api.search(query).pipe(
      catchError(() => EMPTY), // keeps search$ alive
    ),
  ),
);
?Unknown authorNov 30, 2026, 2:13 PM

For instance, here is an entry: "while - skipUntil + takeUntil":

#RxJS #Angular #TypeScript #WebDev

?Unknown authorNov 27, 2026, 3:58 PM

I think you probably should never use `forkJoin`? Used to be a stereotypical interview question where `forkJoin` was the answer (it wasn't correct)

#RxJS #Angular #TypeScript #WebDev

// 1. One failing request kills the whole batch
// 2. One stream that never completes = hangs forever
forkJoin({
  user: this.api.getUser(),      // completes -> OK
  theme: this.themeStore.theme$, // BehaviorSubject -> NEVER completes!
}).subscribe(console.log);       // logs nothing, ever
?Unknown authorNov 25, 2026, 11:48 AM

Another piece of elegant RxJS: rate-limit stuff (in this case, too many toast notifications) with yet another single line of code.

Love how RxJS can help solve complex issues so easily. Possibilities are literally endless

#RxJS #Angular #TypeScript #WebDev

zip(this.alerts$, interval(1500)).pipe(
  map(([alert]) => alert),
).subscribe((alert) => this.toast.show(alert));
// 5 errors arrive at once -> shown 1.5s apart, none dropped
?Unknown authorNov 24, 2026, 2:28 PM

You know what, there are so many RxJS operators and most of them have actual good use cases

Do you know the difference between `scan`/`reduce`? And when to use what

#RxJS #Angular #TypeScript #WebDev

items$ = this.page$.pipe(
  exhaustMap((page) => this.api.getOrders(page)),
  scan((all, next) => [...all, ...next], [] as Order[]),
);
?Unknown authorNov 24, 2026, 12:18 PM

No matter how many layers of abstraction you build around them, it all comes down to exhaustMap vs concatMap vs switchMap... can you show which use case goes to which operator?

#RxJS #NgRx #Angular #WebDev

Quiz infographic: Match three RxJS flattening operators — 1 switchMap (cancel previous, run latest), 2 exhaustMap (ignore new until current finishes), 3 concatMap (queue and run in strict order) — to three shuffled use cases: A Checkout / Pay Now button double-click, B Ordered autosave queue, C Search-as-you-type.
?Unknown authorNov 23, 2026, 3:23 PM

It would be great to make your coding agents produce code heavily leaning into things like this, so you can both iterate quickly and still hold a decent understanding of your codebase

#RxJS #Angular

?Unknown authorNov 17, 2026, 2:18 PM

Also, can you guess why I used `effect` here?

#Angular #Signals #RxJS #WebDev

?Unknown authorNov 17, 2026, 11:29 AM

Wait, RxJS has a `groupBy` operator?

This changes everything!

#RxJS #Angular #TypeScript #WebDev

TypeScript code in a dark editor tab named feed.ts. A Feed component lists posts with @for, each with a Like button that calls likes$.next({ id: post.id, liked: !post.liked }). likes$ is a Subject. In the constructor, likes$ is piped through groupBy((like) => like.id), then mergeMap((post$) => post$.pipe(switchMap((like) => this.api.setLiked(like)))), all three lines highlighted, under the comment "liking post 2 no longer cancels the request for post 1". It ends with takeUntilDestroyed() and subscribe().
?Unknown authorNov 10, 2026, 12:16 PM

There were a lot of super popular RxJS patterns that are no longer necessary with the advent of signals

Here are some of them:

#Angular #RxJS #Signals

Infographic titled "Where did all my RxJS operators go?" with the line "In Angular 22, most of them became signals." Five RxJS operators, each with an arrow down to the Angular signal API that replaced it: BehaviorSubject to signal(), combineLatest to computed(), debounceTime to debounced(), switchMap to httpResource(), and subscribe to effect(). Below, a timeline labeled "Still RxJS" with exhaustMap, concatMap, retry and webSocket.
?Unknown authorNov 9, 2026, 4:29 PM

But did you know JavaScript has an analogous function? With `Array.fromAsync` you can turn any asynchronous iterable into an array:

#JavaScript #RxJS #TypeScript #WebDev

?Unknown authorNov 6, 2026, 4:33 PM

Modern enterprise apps nowadays often involve launching long-running jobs and then polling the API for status

With RxJS you just need one flag (inclusive) to read and react to the final result:

#Angular #RxJS #WebDev

Angular code in export.ts. A component with selector 'app-export' and the template: <button (click)="start$.next()">Export report</button>, then @let job = exportJob(); @if (job?.status === 'running') shows <progress [value]="job.progress" max="100">, @else if (job?.status === 'done') shows <a [href]="job.fileUrl">Download report</a>. In class Export: private readonly http = inject(HttpClient); readonly start$ = new Subject<void>(); readonly exportJob = toSignal(this.start$.pipe(switchMap(() => this.http.post<{ id: string }>('/api/exports', {})), switchMap(({ id }) => timer(0, 2000).pipe(switchMap(() => this.http.get<ExportJob>(`/api/exports/${id}`)), takeWhile((job) => job.status === 'running', true))))). The takeWhile line is highlighted.
?Unknown authorNov 5, 2026, 4:55 PM

If this is not how your coding agent implements a "you have been inactive" popup in your Angular app, you need to switch your agent/model ASAP 😄

#Angular #RxJS #WebDev

Angular code in app.ts. const ACTIVE_EVENTS = ['click', 'scroll', 'keydown', 'mousemove']. A component with selector 'app-root' and the template: @if (isInactive()) { <p class="notice">You have been inactive for a while 👀</p> }. In class App: readonly isInactive = toSignal(merge(...ACTIVE_EVENTS.map((event) => fromEvent(document, event))).pipe(startWith(null), switchMap(() => timer(10_000).pipe(map(() => true), startWith(false)))), { initialValue: false }). The merge line and the switchMap line are highlighted.
?Unknown authorNov 5, 2026, 1:45 PM

Retrying after an error is pretty much good UX by itself. However, you cannot keep hammering an endpoint with requests until it works (it might never work 😆 )

Thankfully, it is very easy to implement an exponential backoff with a combo of retry + timer in RxJS:

#RxJS #Angular #WebDev

Angular code in report.service.ts. An @Injectable({ providedIn: 'root' }) class ReportService with private readonly http = inject(HttpClient). Its getReport() method returns this.http.get<Report>('/api/report').pipe(retry({ ... })). The retry config (highlighted) has count: 3, with the comment "give up after 3 retries", and delay: (error: HttpErrorResponse, attempt) => { ... }. Inside, with the comment "a 404 won't fix itself, fail right away": if (error.status < 500) { return throwError(() => error); }. Then return timer(2 ** attempt * 1000), with the comment "wait 2s, 4s, 8s" (highlighted).
?Unknown authorOct 26, 2026, 4:08 PM

What operator would you choose?

I would use `auditMap`, but there is a slight problem: that operator does not exist! It is, however, quite easy to build by combining a `throttle` and `concatMap` and creating a deferred Observable out of them:

#Angular #RxJS #TypeScript #WebDev

TypeScript code in audit-map.ts, a custom RxJS operator built from throttle and concatMap; the throttle line is highlighted:

import { concatMap, defer, finalize, from, Subject, throttle } from 'rxjs';
import type { ObservableInput, OperatorFunction } from 'rxjs';

export function auditMap<T, R>(
  project: (value: T) => ObservableInput<R>,
): OperatorFunction<T, R> {
  return (source) =>
    defer(() => {
      const done = new Subject<void>();

      return source.pipe(
        // first value goes through, then only the latest until `done`
        throttle(() => done, { leading: true, trailing: true }),
        concatMap((value) =>
          from(project(value)).pipe(finalize(() => done.next())),
        ),
      );
    });
}An Angular component in note-editor.ts that autosaves a textarea with the custom auditMap operator; the auditMap line is highlighted:

@Component({
  selector: 'app-note-editor',
  imports: [ReactiveFormsModule],
  template: `<textarea [formControl]="content"></textarea>`,
})
export class NoteEditor {
  private readonly notesApi = inject(NotesApi);
  readonly content = new FormControl('', { nonNullable: true });

  constructor() {
    this.content.valueChanges
      .pipe(
        auditMap((text) => this.notesApi.save(text)),
        takeUntilDestroyed(),
      )
      .subscribe();
  }
}