-
Notifications
You must be signed in to change notification settings - Fork 27.4k
angular.equals/merge does not support circular reference #14512
Comments
Similar issues/PRs have been "shot down" in the past (e.g. #7839, #11653). E.g. see #7839 (comment) for the reasoning. There is also #10096 that would provide another way to solve this. What is your usecase, btw ? |
We are trying to optimize the uses of the $watchers in one application where the number are quite extensive, we were switching to use scope.$watch with objectEquality == true which relies on angular.copy and angular.equals, while doing so we found 3 scenarios in our application where objects with circular references were seem:
The optimization we have implemented works fine as long as the angular.equals doesn't find an object with a circular reference, but that is not the case, actually it is quite the opposite, circular references are find a lot, and we don't have too much options to actually fix the ones that are identified so far. |
Switching to |
hehehe, agree, but in our particular case it looks like the way to go, actually we have applied the change along with a patched version of angular.js to avoid circular references in DEV environment, and the approach of using objectEquality: true seems to be giving performance benefits that we need, still going to production with a patched version of angular.js doesn't seem to be feasible. |
It seems that one can patch this efficiently for their own use case if you know what you're looking for. In my application, I've written an ORM that uses circular structures liberally, but I know what comparisons fail, so I can short circuit angular.equals where necessary: After
In my use case, there's a Obviously patching the actual framework sucks, but it's better than being shot down and not having any solution whatsoever :-) |
I'm running into the same issue. My use case is: when a user wants to edit a model I make a copy of if so that any changes can be canceled. Then when the user tries to save their changes I compare the copy with the original to see if anything actually needs to be saved. |
Same for me, I'm trying to do: function updateEntity(entity, changes) {
const entityToSave = angular.merge({}, entity, changes);
return entityResource.update(entityToSave).$promise
.then(updatedEntity => {
entity = angular.merge({}, entity, updatedEntity);
console.log('entity was updated.');
return updatedEntity;
})
.catch(error => {
console.error('entity could not be updated.');
return error;
});
} … which would be very convenient but would include circular references. Update: Using _.assignIn() for now. |
This is the same issue as reported in #2618, but for angular.merge and angular.equals.
An example can be seen at: http://plnkr.co/edit/j3qz1Rt3ABOXyWw0KpgB?p=preview
The text was updated successfully, but these errors were encountered: