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

signalState changes passed array to map #4316

Closed
1 of 2 tasks
dyeske61283 opened this issue May 7, 2024 · 3 comments · Fixed by #4327
Closed
1 of 2 tasks

signalState changes passed array to map #4316

dyeske61283 opened this issue May 7, 2024 · 3 comments · Fixed by #4327

Comments

@dyeske61283
Copy link

Which @ngrx/* package(s) are the source of the bug?

signals

Minimal reproduction of the bug/regression with instructions

https://stackblitz.com/edit/angular-17-starter-project-cexglh?file=src%2Fmain.ts

Expected behavior

The type of the passed state should not change - even if no deep signals are created. (Looking at the unit test here:

it('does not create deep signals for an array', () => {
)

Versions of NgRx, Angular, Node, affected browser(s) and operating system(s)

@ngrx/signals: 17.2.0
@angular: 17.0.4

Other information

No response

I would be willing to submit a PR to fix this issue

  • Yes
  • No
@markostanimirovic
Copy link
Member

signalState as well as withState should accept a record/dictionary as an input argument. There is no benefit of using them with arrays. at the root level.

There are two options that you can use:

  1. const numbers = signal([1, 2, 3]);
  2. const state = signalState({ numbers: [1, 2, 3] });

@dyeske61283
Copy link
Author

@markostanimirovic we are using the second option now, but some level of error or warning would have been nice in the development or at least in the documentation.

@dreamstar-enterprises
Copy link

dreamstar-enterprises commented May 13, 2024

Will deep signals be supported for maps like this? E.g. so computed signals can be created on specific keys, whose values might be arrays?

type FilterModalState = {
  filterModalMap: {
    [modalType: string]: {
      modalType: string;
      selectedItemsState: string[];
      cancelOrResetLabel: string;
    }
  }
};

Currently, I think only this works

type FilterModalState = {
  filterModalMap: {
    modalData: {
      modalType: string;
      selectedItemsState: string[];
      cancelOrResetLabel: string;
    }
  }
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants