Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/k3nsei/ngx-signal-store-query

Signal Store feature that bridges with Angular Query
https://github.com/k3nsei/ngx-signal-store-query

angular angular-query signal-store signal-store-feature signals state-management

Last synced: about 2 months ago
JSON representation

Signal Store feature that bridges with Angular Query

Awesome Lists containing this project

README

        

# ngx-signal-store-query

Signal Store feature that bridges with Angular Query

## Simple Example

#### Create Store

```typescript
import { signalStore, withState } from '@ngrx/signals';
import { withQuery } from '@ngx-signal-store-query/core';
import { lastValueFrom } from 'rxjs';

import { ApiService } from './api.service';

export const ExampleStore = signalStore(
withState({ categoryId: 1 }),
withQuery('example', (store) => {
const apiService = inject(ApiService);

return () => {
const categoryId = store.categoryId();

return {
enabled: !!categoryId,
queryKey: ['category', { id: categoryId }],
queryFn: () =>
lastValueFrom(apiService.getCategory$(categoryId)).catch((error) => {
console.error(error);

return null;
}),
};
};
}),
);
```

#### Use it in component

```typescript
import { JsonPipe } from '@angular/common';
import { ChangeDetectionStrategy, Component, inject } from '@angular/core';

import { ExampleStore } from './example.store.ts';

@Component({
standalone: true,
selector: 'app-example',
template: `


Loading: {{ store.exampleQuery.isLoading() }}
Fetching: {{ store.exampleQuery.isFetching() }}
Data:
{{ store.exampleQuery.data() | json }}

`,
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [JsonPipe],
})
export class ExampleComponent {
public readonly store = inject(ExampleStore);
}
```