diff --git a/apps/demo/src/app/app.component.html b/apps/demo/src/app/app.component.html index a18faa3..36e225b 100644 --- a/apps/demo/src/app/app.component.html +++ b/apps/demo/src/app/app.component.html @@ -28,6 +28,7 @@ withConditional withMutation rxMutation (without Store) + withResource diff --git a/apps/demo/src/app/lazy-routes.ts b/apps/demo/src/app/lazy-routes.ts index ba4c66e..b202543 100644 --- a/apps/demo/src/app/lazy-routes.ts +++ b/apps/demo/src/app/lazy-routes.ts @@ -75,4 +75,11 @@ export const lazyRoutes: Route[] = [ (m) => m.CounterRxMutation, ), }, + { + path: 'with-resource', + loadComponent: () => + import('./with-resource/with-resource.component').then( + (m) => m.WithResourceComponent, + ), + }, ]; diff --git a/apps/demo/src/app/with-resource/with-resource.component.ts b/apps/demo/src/app/with-resource/with-resource.component.ts new file mode 100644 index 0000000..43b5d42 --- /dev/null +++ b/apps/demo/src/app/with-resource/with-resource.component.ts @@ -0,0 +1,46 @@ +import { withResource } from '@angular-architects/ngrx-toolkit'; +import { JsonPipe } from '@angular/common'; +import { httpResource } from '@angular/common/http'; +import { Component, inject } from '@angular/core'; +import { signalStore, withState } from '@ngrx/signals'; +import { Flight } from '../shared/flight'; + +const url = 'https://demo.angulararchitects.io/api/flight?from=Paris&to='; + +export const FlightStore = signalStore( + withState({ flightTo: 'New York' }), + withResource(({ flightTo }) => httpResource(() => `${url}${flightTo()}`)), + withResource(({ flightTo }) => ({ + list: httpResource(() => `${url}${flightTo()}`, { + defaultValue: [], + }), + })), +); + +@Component({ + selector: 'demo-with-resource', + imports: [JsonPipe], + template: `, +

withResource

+ withResource doc page + +

Single Resource

+
value: {{ store.value() | json }}
+
status: {{ store.status() }}
+
error: {{ store.error() | json }}
+
hasValue: {{ store.hasValue() }}
+ +

Named Resource

+
{{ store.listValue() | json }}
+
status: {{ store.listStatus() }}
+
error: {{ store.listError() | json }}
+
hasValue: {{ store.listHasValue() }}
`, + providers: [FlightStore], +}) +export class WithResourceComponent { + store = inject(FlightStore); +}