feat: remove Immutable utility type from core interfaces #42
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.
This substantial change in signature eliminates a core dependency on
Immutable
, with the aim thatImmutable
is elective by the creators of a store. It's still strongly recommended, (but not enforced).This is important if the immutable operations you are using on your store state come from a world without compile-time immutability. Even though they in practice never make changes, APIs often declare e.g.
doTheThing<Arr extends number[]>(entries:Arr)
notdoTheThing<Arr extends readonly number[]>(entries:Arr)
which would be required for it to accept anImmutable<number[]>
.However, operating WITHOUT Immutable should be done with care, and because you prefer THAT hassle (incautious mutation of state which shouldn't be mutated) versus the hassle of
readonly
markers throughout your data.So instead of their being magic to transform your
State
into anImmutable<State>
, with all reads and selected values being wrapped inImmutable<>
with a signature like this...You opt-in explicitly, which has no effect on any calls YOU make, but radically simplifies the type gymnastics for special cases since
Immutable
is in the original type you specify, rather than needing selective transforms as read/write boundaries are crossed.Potentially there could be a utility type to simplify opting into immutability to embody the recommendation, like...