Minimize what data is stored in vm.annotation
Remove all the properties that don't need to be in vm.annotation from vm.annotation. This means removing all the read-only properties (id, target, updated, user) and leaving only the read-write ones that the templates write via `ng-model` (vm.annotation.tags and vm.annotation.text). The templates still do need read-only access to id, target, updated and user, but rather than _duplicating_ these values by copying them from domainModel to vm.annotation, instead add accessor methods vm.id() etc that just return the values from domainModel. This has two advantages: 1. Data is not duplicated between domainModel and vm.annotation. 2. It's clear that these fields are read-only, since the templates literally can't write them, at least in the case of id, user and updated target is unfortunately a mutable object so the templates could still mutate it. vm.target() could return a copy to avoid this but I haven't gone that far.
Showing
Please register or sign in to comment