vaadin / platform

Vaadin platform 10+ is a Java web development platform based on Vaadin web components. If you don't know to which repository your bug report should be filed, use this and we'll move it to the right one.
https://vaadin.com
563 stars 79 forks source link

Immutable generated data structures #2371

Open gilberto-torrezan opened 3 years ago

gilberto-torrezan commented 3 years ago

It's recommended and considered a best practice to avoid mutating data received from the endpoints. This is a breaking change that will introduce the readonly flag and ReadonlyArray to the attributes of generated data structures.

With this change, applications written in Fusion will be safer by design.

Refer to this ticket with more technical details.

Use cases

As a developer, when consuming data from a Fusion endpoint and cascading the data over the application, you are safe to know that the received data is immutable, no matter the logic in your application. It needs to be a conscious decision from the developer to create a mutable clone of the data if needed.

Acceptance criteria

Documentation:

https://vaadin.com/docs/latest/fusion/application/accessing-backend/#read-only-access

How to test?

gilberto-torrezan commented 3 years ago

Initially this change was meant to be the new default in V22 projects, but after some rounds of internal testing, the feedback was that it gets more in the way than it helps, especially when using MobX for state management. It would also create unnecessary friction for developers migrating from V21.

So we won't be pushing this for V22, but consider it as an option (not the default) for V23.