Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use this with class based signalStore of Angular #1831

Open
Jagan-P opened this issue Feb 11, 2025 · 0 comments
Open

How to use this with class based signalStore of Angular #1831

Jagan-P opened this issue Feb 11, 2025 · 0 comments

Comments

@Jagan-P
Copy link

Jagan-P commented Feb 11, 2025

I found this extension which enables it for functional store but couldn't find a way to use it with class based store.

import { Injectable, computed, inject } from '@angular/core';
import { pipe, shareReplay } from 'rxjs';
import { signalStore, withState, withMethods, patchState } from '@ngrx/signals';
import { rxMethod } from '@ngrx/signals/rxjs-interop';
import { switchMap, tap } from 'rxjs/operators';

@Injectable({ providedIn: 'root' })
export class HardwareDeviceDetailsStore extends signalStore(
  withState(initialState),
  withMethods((store, hardwareDeviceService = inject(HardwareDeviceService)) => ({
    loadDeviceDetails: rxMethod<string>(
      pipe(
        tap(() => patchState(store, { isLoading: true, hasError: null })),
        switchMap((deviceId) =>
          hardwareDeviceService.getHardwareDeviceVariantGroupsById(deviceId).pipe(
            tap((response) => {
              if (response.error) {
                patchState(store, { hasError: true, isLoading: false });

                return;
              }

              patchState(store, { data: response.result, isLoading: false });
            }),
            shareReplay(1),
          ),
        ),
      ),
    ),
    clearDeviceDetails: () => patchState(store, { data: null, isLoading: false, hasError: false }),
  })),
) {}

I have raised an issue with them too but no idea if it is something they can do or you both should do.

angular-architects/ngrx-toolkit#142

@Jagan-P Jagan-P changed the title How to use this with signalStore of Angular How to use this with class based signalStore of Angular Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant