包详细信息

@ngx-signal-store-query/core

k3nsei488MIT0.7.1

Signal Store feature that bridges with Angular Query

Angular, Signals, State Management, Signal Store

自述文件

ngx-signal-store-query

Signal Store feature that bridges with Angular Query

Simple Example

Create Store

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

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: `
    <pre>
      Loading: {{ store.exampleQuery.isLoading() }}
      Fetching: {{ store.exampleQuery.isFetching() }}
      Data:
      {{ store.exampleQuery.data() | json }}
    </pre>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [JsonPipe],
})
export class ExampleComponent {
  public readonly store = inject(ExampleStore);
}

更新日志

Changelog

0.7.1 (2025-05-29)

Miscellaneous Chores

  • deps-dev: bump angular cli from v19.2.10 to v20.0.0 (339e024)

0.7.0 (2025-03-28)

⚠ BREAKING CHANGES

  • deps: Versions of @tanstack/angular-query-experimental older than v5.69.2 are no longer supported

Miscellaneous Chores

  • deps-dev: bump angular cli from v19.2.0 to v19.2.5 (3bcfec9)
  • deps: bump @tanstack/angular-query-experimental from v5.66.9 to v5.69.2 (3bcfec9)

0.6.0 (2025-02-21)

⚠ BREAKING CHANGES

  • deps: Stopped supporting versions of @ngrx/signals that are older than v19.0.1

Miscellaneous Chores

  • deps: bump @ngrx/signals from v19.0.0 to v19.0.1 (5d91d7a)

0.5.0 (2024-12-21)

⚠ BREAKING CHANGES

  • migrate to ngrx signals v19
  • bump tanstack angular query to 5.61.0

Features

  • bump tanstack angular query to 5.61.0 (a73f6df)
  • migrate to ngrx signals v19 (1720b42)

0.4.0 (2024-11-20)

⚠ BREAKING CHANGES

  • Minimum supported version of TanStack Angular Query changed to 5.61.0

Features

  • bump tanstack angular query to 5.61.0 (a73f6df)

0.3.0 (2024-08-17)

Features

  • only infer types of inputs and outputs (25615c8)
  • simplify types (25615c8)

Bug Fixes

  • demo: typos in error messages (b44810d)

0.2.0 (2024-08-16)

Features

  • add withMutation feature (1d6b3a8)
  • omit need to unwrap query ref (1d6b3a8)

0.1.0 (2024-08-11)

Features