So I have this REST library that I am developing and someone brought the fact that because I am using set()/get() methods to work with the model's data, that it makes it hard to bind the model's data to stuff like ng-model (https://github.com/nucleus-angular/rest/issues/16). Now I already posted a workaround which is getting the JSON of the model data, bind using that, and then watch that variable in the controller (or wherever) and call set(scope.jsonData) when it changes but of course this is not the cleanest solution.
The primary reason for the set() method is because I want to be able to track what properties have changed since the last sync() so that when I perform a PATCH, I can only send the changed properties and not everything.
One cross browser solution that has been suggested from the person reporting this issue is to watch the data within the model itself and when it changes, I can update the list of dirty properties. This way I can expose the data natively which will allow people to bind to the model data directly. Assuming I understand what he means, that would mean injecting the $rootScope, create a new $scope from that, and the adding the $watch to that scope for each generated model. Not sure how this will effect performance with a lot of models.
Another idea I have that I have seen implemented in other (server-side) ORM solutions is to keep a copy of the remoteData with the model. Everytime I sync the data, I copy the current data as the remote data and that way the next time I do a sync() with the PATCH method, I can diff the 2 objects and only send the changed data. The downside here is now I have 2 copies of the model data instead of one so increase memory and probably increased chance of memory leak.
Considering this library is specifically tied to AngularJS and I don't have to worry about supporting multiple frameworks, which solution would you think would provide the best performance/least issues?