The Real Fullstack

The Stale Search Results

The user typed “kafka”. The page shows results for “kaf”. Nobody typed “kaf” last.

エンジニア8 分タイムラインシミュレーターコード課題
angularrxjstypescriptreacthttp

この課題はまだ日本語に翻訳されていません。英語版を表示しています。

ミッション:Reproduce the race between overlapping requests, then pick a strategy that always shows results for the latest query, quickly, without hammering the API.背景 · 学習目標 ▾

Larkspur's event search sends a request on every keystroke. The backend is usually fast, but some short queries are expensive and slow. Users report that results sometimes “jump back” to an older search after a moment.

ミッション: Reproduce the race between overlapping requests, then pick a strategy that always shows results for the latest query, quickly, without hammering the API.

学習目標

  • Explain why responses can arrive out of order.
  • Compare mergeMap, concatMap, exhaustMap and switchMap.
  • Cancel stale requests and debounce input.
シミュレーションシミュレーション値

シミュレーションを実行すると出力が表示されます。

シミュレーションを実行
readonly results = toSignal(  this.query.valueChanges.pipe(    mergeMap((q) => this.api.search(q)),   // every response is rendered, in arrival order  ), { initialValue: [] });

簡略化

Four keystrokes with fixed latencies. Real latencies vary, which makes the race intermittent and hard to reproduce. 教育用モデルです。数値は挙動を示すためのもので、ベンチマークではありません。

コンセプト

先に取り組むと役立つ課題

関連する課題

参考資料