Patching allows modifying specific properties of an object without changing the original object. It's like creating a list of changes that can be stored and even sent over the network to the API. The list of changes can then be applied to one or multiple objects.
All AutoEncoder objects (Writing AutoEncoder classes) are patchable by default. Other objects can be made patchable by implementing the Patchable interface.
This is how it works:
Why?
In the UI, you can maintain three variables simultaneously: the original object, the patch, and the patched object. Only the patch gets modified as changes are being made in the UI. While the patched object updates automatically (using a computed property in Vue). The patch is sent to the API over the network when the save button is clicked.
This pattern enables complex nested editing views. For example, when editing a member, you track their patch. Within the same view, you can open another view to edit the member's emergency contact. Instead of saving the emergency contact's changes to the network, you can pass the emergency contact's patch back to the member editing view. If you cancel the edit, you simply discard the emergency contact's patch.
The full pattern is described in UI: Edit views
Simple Example: