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

fix(signals): enable withProps to handle Symbols #4656

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

rainerhahnekamp
Copy link
Contributor

Resolve an issue in signalStore that prevented Symbols from being added as property keys when merging
different features.

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[x] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

The value is just undefined.

Closes #4655

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Resolve an issue in `signalStore` that prevented Symbols
from being added as property keys when merging
different features.
Copy link

netlify bot commented Jan 3, 2025

Deploy Preview for ngrx-io ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit c747174
🔍 Latest deploy log https://app.netlify.com/sites/ngrx-io/deploys/678ba2c2f15bbf0008f2b25b
😎 Deploy Preview https://deploy-preview-4656--ngrx-io.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Comment on lines +52 to +70
it('allows symbols as props', () => {
const SECRET = Symbol('SECRET');

const Store = signalStore(withProps(() => ({ [SECRET]: 'secret' })));
const store = TestBed.configureTestingModule({ providers: [Store] }).inject(
Store
);

expect(store[SECRET]).toBe('secret');
});

it('allows numbers as props', () => {
const Store = signalStore(withProps(() => ({ 1: 'Number One' })));
const store = TestBed.configureTestingModule({ providers: [Store] }).inject(
Store
);

expect(store[1]).toBe('Number One');
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The with-props.spec.ts file should contain only unit tests for the withProps function. Check other tests from this file for more info.

These (integration) tests with SignalStore should be added to the signal-store.spec.ts: https://github.com/ngrx/platform/blob/main/modules/signals/spec/signal-store.spec.ts#L150


Let's also add a test that verifies that a symbol prop is available in the next feature, not only in the final store:

signalStore(
  withProps(() => ({ [symbol]: 1 })),
  withMethods((store) => store[symbol]...
)

We should also have tests to verify:

  • Behavior when state slice/method name is a symbol.
  • Immutability checks for symbol state slices. I don't think the current check will work - deepFreeze uses Object.getOwnPropertyNames.
  • Assertion for duplicate keys defined as symbols. Currently, it will not work because Object.keys is used with the assertUniqueStoreMembers function.

modules/signals/src/signal-store.ts Outdated Show resolved Hide resolved
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

Successfully merging this pull request may close these issues.

withProps doesn't allow Symbols as keys
3 participants