feat: make signalStore entries starting with _ not available outside of the store (interface, first level) #4309
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
As (more or less) mentioned in #4283 and #4210, providers returned by the factory
signalStore
are currently lacking some sort on encapsulation.As I see it, there are 2 problems:
patchState
andgetState
are defined as utilities applicable on both objects returned bysignalStore
andsignalState
. This is good for reusability, but it comes with the undesired side effect of making a signalStore patchable anywhere (like in components consuming it). Considering the store mental model,patchState
andgetState
should probably be available only in methods / hooks.The goal of this PR is targeting point 1, following (hopefully) the suggestion in #4210 (comment). Here is a use case where the feature would come in handy (there are many others):
With this PR, prefixing any root slice of the state / computed / method by
_
should make it unavailable (ts interface) in the returnedsignalStore
provider.PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What is the current behavior?
Providers returned by the factory
signalStore
are currently lacking encapsulationPartially address #4283 and #4210
What is the new behavior?
Prefixing any root slice of the state / computed / method by
_
should make it unavailable (ts interface) in the returnedsignalStore
provider.Does this PR introduce a breaking change?