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

Flag to enforce immutable entities #3

Open
JanMalch opened this issue Nov 18, 2018 · 1 comment
Open

Flag to enforce immutable entities #3

JanMalch opened this issue Nov 18, 2018 · 1 comment
Labels
discussion An issue that discusses design decisions. help wanted Extra attention is needed

Comments

@JanMalch
Copy link
Collaborator

Is it useful to add a flag in the super call of your store that enforces immutable entities? The object containing the data is immutable but the entities itself aren't required to be immutable.

This could simply be checked by adding current !== updated after this.onUpdate and throwing an error depending on the result.

Also: what should the default value for the flag be, if it's wanted. Or no default value?

@JanMalch JanMalch added help wanted Extra attention is needed question Further information is requested discussion An issue that discusses design decisions. and removed question Further information is requested labels Nov 18, 2018
@markwhitfeld
Copy link
Member

You could use the DeepReadonly<T> typescript type (available since 2.8) to make this a design time check. ie.

abstract onUpdate(current: DeepReadonly<T>, updated: Partial<T>): T;

potentially even:

abstract onUpdate(current: DeepReadonly<T>, updated: DeepReadonly<Partial<T>>): T;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion An issue that discusses design decisions. help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants