platform
platform copied to clipboard
feat(signals): Protection for Overriding Properties
This Proof of Concept intrdocues a feature which prevents that feature override properties (state
, signals
, methods
).
It does that by adding a conditional type NoOverride
which as a constraint to the parameters of signalState
.
Example:
signalState(
withState({ id: 1, name: 'hallo', prettyName: 'hi' }),
withComputed((store) => {
return {
prettyName: computed(() => store.name()),
};
})
)
This would fail to compile because prettyName
is overriden.
The overriding protection is enabled by default. It is very likely that overriding doesn't happen on purpose.
An opt-out is also possible via the configuration:
signalState(
{allowOverrides: true},
withState({ id: 1, name: 'hallo', prettyName: 'hi' }),
withComputed((store) => {
return {
prettyName: computed(() => store.name()),
};
})
)
PR Checklist
Please check if your PR fulfills the following requirements:
- [x] The commit message follows our guidelines: https://github.com/ngrx/platform/blob/main/CONTRIBUTING.md#commit
- [x] Tests for the changes have been added (for bug fixes / features)
- [ ] Documentation has been added / updated (for bug fixes / features)
PR Type
What kind of change does this PR introduce?
[ ] Bugfix
[x] 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?
Features can override properties of other features.
Closes #
What is the new behavior?
By default we get a compilation error. Allowing overrides is possible via the configuration.
Does this PR introduce a breaking change?
[x] Yes
[ ] No
Honestly, I think that developers would welcome that breaking change. Overriding properties can cause bugs which might be hard to detect.
Other information
This is just a POC. If accepted, it has to be integrated into the original withState
and probably signalStoreFeature
.
Deploy Preview for ngrx-io ready!
Built without sensitive environment variables
Name | Link |
---|---|
Latest commit | 00bb1996fd6a63b14e88371366549478add3f9c5 |
Latest deploy log | https://app.netlify.com/sites/ngrx-io/deploys/6595ac94d63cae0008b95a2f |
Deploy Preview | https://deploy-preview-4199--ngrx-io.netlify.app |
Preview on mobile | Toggle QR Code...Use your smartphone camera to open QR code link. |
To edit notification comments on pull requests, go to your Netlify site configuration.
@markostanimirovic, since I don't know which process you prefer, I only created a PR.
If you prefer to open an issue first and do all the discussions there, please let me know.
closing this PR in favor of https://github.com/ngrx/platform/pull/4424