I am writing an application in Angular JS (1.5), and I need to be able to track a model for changes (updates/deletes/additions). For example, I have an ng-model that holds an array of user pets. This array has 5 pets, but the user (from the front end) can delete pets from that model or add more pets. I want to be able to keep track of what pets were removed from the array and what pets were added, so that I can remove the deleted pets from the database, leave the unchanged pets, and add the new pets. I would assume I need 2 operations for this - delete and insert, but I am not sure how to go about this.
How would I best keep track of these changes in Angular? I would like to follow the "unit of work" pattern, but I am not sure how to go about this in Angular and Javascript. I was thinking of using 3 arrays; one for existing data, one for deleted data, and one for new data. I would then send the deleted and inserted data for the post request. Does that make sense?