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 withDevtools with a class based signal store that extends signalStore #142

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

Comments

@Jagan-P
Copy link

Jagan-P commented Feb 11, 2025

I have this class based signalStore,

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 }),
  })),
  
) {}

Upon adding withDevtools I see there are some type issues.

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 }),
  })),
  withDevtools("store")
) {}

'extends' clause of exported class 'HardwareDeviceDetailsStore' has or is using private name 'SIGNAL'.ts(4020)

Image
@abhijit-chikane
Copy link

Image

import { withDevtools } from '@angular-architects/ngrx-toolkit';
use it like storeFeature and I have added condition as I don't want it to use it in production

@rainerhahnekamp
Copy link
Collaborator

@Jagan-P, do you also get the error without. withDevtools()?

@Jagan-P
Copy link
Author

Jagan-P commented Feb 17, 2025

Image

import { withDevtools } from '@angular-architects/ngrx-toolkit'; use it like storeFeature and I have added condition as I don't want it to use it in production

@abhijit-chikane your example is not a class based signalStore. Mine is a class based signal store.

@Jagan-P
Copy link
Author

Jagan-P commented Feb 17, 2025

@Jagan-P, do you also get the error without. withDevtools()?

@rainerhahnekamp no I don't see any errors once I remove the withDevtools(). Will create a fiddle or plunkr to reproduce this.

@rainerhahnekamp
Copy link
Collaborator

Will create a fiddle or plunkr to reproduce this.

Yes please. Do that.

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

3 participants