entity-state icon indicating copy to clipboard operation
entity-state copied to clipboard

Flag to enforce immutable entities

Open JanMalch opened this issue 5 years ago • 1 comments

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 avatar Nov 18 '18 16:11 JanMalch

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;

markwhitfeld avatar Nov 24 '18 22:11 markwhitfeld