← Webalkalmazás fejlesztők adatlapja
Nézd meg, miben segít
Angular RxJS-adatfolyamok
Tudatos megszakítással, sorrenddel és hibakezeléssel hangolja össze az Angular aszinkron eseményeit.
angular-rxjs
Ezt a skillt használó csapattagok
Mikor hasznos?
Akkor használd, ha keresések versenyeznek, mentések ütköznek vagy egy hiba után leáll a kezelőfelület.
Miben segít neked?
- A kívánt megszakítási, sorba állítási vagy párhuzamos működéshez választ operátort.
- Hiba után is működőképesen tartja az eseményfolyamot, látható állapotokkal.
- Elkerüli a dupla HTTP-hívásokat és megszünteti a lejárt feliratkozásokat.
Például ezt kérheted
Javítsd az élő keresést: régi válasz ne győzzön, hiba után lehessen keresni, kilépéskor álljon le a munka. Az első kérés legyen lassú, a második gyors. Hálózati hiba után is működjön az új keresés, duplán létrejövő feliratkozások nélkül.
Részletes dokumentáció
Itt a skill eredeti útmutatóját, példáit és ellenőrzési szempontjait olvashatod az eredeti nyelven.
Összecsukás
RxJS & Async Data Flows
Model asynchronous streams declaratively with the flattening, combination and error-handling operators that match the operation's cancellation and ordering semantics.
1. Choosing the right higher-order flattening operator
- Never nest
.subscribe()calls inside another.subscribe(); compose streams with flattening operators based on concurrency and cancellation behavior:switchMap: cancels the previous inner request when a new outer value arrives. Use for reads, typeahead searches, route/filter changes and polling. Never useswitchMapblindly on non-idempotent writes whose server completion matters.exhaustMap: ignores new outer emissions while the current inner observable is active. Use for form submissions, login buttons and one-at-a-time triggers to prevent double submit.concatMap: queues inner observables sequentially in order. Use when every write or step must complete in strict order.mergeMap: runs inner observables concurrently. Use only when parallel execution is safe and order does not matter.
- Remember that cancelling an HTTP observable on the client aborts the browser request but does not roll back work the server has already started.
2. Error handling and stream survival
- An unhandled error terminates an Observable stream permanently. Inside long-lived streams (such as form
valueChanges, action subjects or route param pipelines), placecatchError(...)on the inner observable insideswitchMap/exhaustMap/concatMapso the outer stream stays alive for subsequent user actions. - Expose explicit loading, error and retry states to the UI instead of swallowing errors with
catchError(() => EMPTY)silently.
3. Multicasting and avoiding duplicate HTTP requests
- Cold observables (including
HttpClientcalls) re-execute per subscriber. When multiple template bindings or derived streams read the same HTTP source, consume it once (via a single@if (data$ | async; as data)/@let,toSignal(), orshareReplay({ bufferSize: 1, refCount: true })).
4. Subscription lifecycle
- Prefer declarative consumption (
asyncpipe ortoSignal()) so Angular manages unsubscription automatically. - For imperative subscriptions, always bound their lifetime with
takeUntilDestroyed(this.destroyRef),firstValueFrom/take(1)(when completion is guaranteed), or explicitSubscriptioncleanup inngOnDestroy.
Before you finish
- No nested
.subscribe()calls;switchMap,exhaustMap,concatMapormergeMapchosen deliberately. -
catchErrorplaced on inner streams so user-driven outer streams do not die on the first error. - No unintended duplicate HTTP requests from multiple subscriptions to a cold stream.
- Every long-lived subscription is cleaned up via
asyncpipe,toSignalortakeUntilDestroyed.
Csomagban lévő fájlok 2
LICENSE.txtSKILL.md
