← Ada adatlapja
AgentAda
1. Signals fundamentals (
2. RxJS and Signals interop (
Angular Signals és állapot
Egyértelmű állapottulajdonost választ, és felesleges másolatok nélkül kapcsolja össze a Signals és RxJS működését.
angular-signals-state
Nézd meg, miben segítMikor hasznos?
Akkor használd, ha több tároló verseng, túl sok az effect, vagy nem frissül a nézet.
Miben segít neked?
- A szükséges legszűkebb komponens-, útvonal- vagy szolgáltatásszinten tárol állapotot.
- Tiszta számítással származtat értékeket és csak olvasható megosztott állapotot ad.
- Ellenőrzi a támogatott API-kat és az átalakított adatfolyamok élettartamát.
Például ezt kérheted
Egyszerűsítsd a termékszűrőket egy állapottulajdonossal, számított összesítéssel és megszakítható kereséssel. Változtasd együtt a kategóriát és az árat, majd töröld mindkettőt. A találatszám számított állapotból kövesse őket, eltérő második másolat 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
Signals & State Management
Match Signals and RxJS to the nature of the state: use Signals for synchronous reactive state and derived UI values, and RxJS for event streams, cancellation and complex async coordination.
1. Signals fundamentals (signal, computed, effect)
- Check the project's Angular version before using signal APIs (
signal/computed/effectin v16–17+,input/output/modelin v17.1+,linkedSignal/resourcein v19+). signal(): own writable synchronous state in the narrowest component or service scope; expose.asReadonly()from services so consumers cannot mutate shared state bypassing service methods.computed(): derive values declaratively (filteredItems,isValid,total).computedgetters must be pure and free of side effects.effect(): use sparingly for true side effects (logging, syncing tolocalStorage, imperative DOM/canvas APIs). Never useeffect()to copy or synchronize state that can be expressed withcomputed()orlinkedSignal().
2. RxJS and Signals interop (@angular/core/rxjs-interop)
toSignal(obs$, { initialValue }): bridge an observable into a synchronous template-friendly signal; call it in an injection context (field initializer or constructor) and remember it subscribes immediately for the component/service lifetime.toObservable(sig): bridge a signal into an RxJS pipeline when you needdebounceTime,switchMapcancellation or multi-step async operators; remembertoObservableemits asynchronously via an internal effect, so intermediate synchronous writes within the same tick coalesce.
3. Shared service and store architecture
- Keep state in the narrowest suitable scope: component-local signals/fields first, route/feature-scoped service or SignalStore/ComponentStore next, and root-level store only for genuine cross-app state.
- Update object and array state immutably (
sig.update(list => [...list, item])) soOnPushcomponents andcomputedconsumers detect changes reliably.
Before you finish
- Every piece of state has a single source of truth; read-only signals or streams exposed from shared services.
- Derived state uses
computed()or pure RxJS operators, nevereffect()state copying. -
toSignal/toObservableused in a valid injection context with clear error and initial-value handling.
Csomagban lévő fájlok 2
LICENSE.txtSKILL.md
