Change entityAspect name to $entityAspect to prevent angularJS.equal in circular reference
Angular is comparing objects by the equal function.
If you have a watch on a breeze entity the entityAspect object will cause the ng.equal function to produce a stack overflow.
objects with the $ prefix are ignored by ng.equal function.
In my case I had an issue with ng-formly and breeze because formly is watching the collection and so also the entityAspect.

-
Ward Bell commented
FWIW, I have long felt we made a fundamental error in making entityAspect a property. It should have been a getter method. Too late now though.
-
Ward Bell commented
Thanks for the deets. I'll take a look at the code you linked
I hasten to add that there is an easy and performant way to detect changes ... listen for property changed, either on the entity itself or on the `EntityManager`.
That's where I'd go and then to see how to drive ng-firmly from that ... if that's possible.
Events always beat watches. The problem with events is setting them up. Breeze does that for free.
I will look at your links soon.
Thanks for the dialog.
-
Kent C. Dodds commented
Hi Ward! BartNet asked me to come on and explain why we're deep watching the model. Here's the code where that happens (for reference): https://github.com/formly-js/angular-formly/blob/master/src/directives/formly-form.js#L114
In prose, angular-formly allows you to dynamically alter the properties of fields. This feature is called expressionProperties (see this egghead.io lesson for more info https://egghead.io/lessons/angularjs-angular-formly-expressionproperties?pl=advanced-angular-forms-with-angular-formly). The expressionProperties are run when any of the model properties change. This is an extremely powerful feature of angular-formly. It also normally results in fewer watches because there's a single watch per form rather than a single watch per expression property.
Based on what you've said though, I don't see this change actually happening anytime soon... People may have to find a way around it...
-
BartNet commented
this is the conversation on ng-formly: https://github.com/formly-js/angular-formly/issues/397
-
BartNet commented
Hi Ward,
I'm using ng-formly (http://docs.angular-formly.com/) to render forms.
And it is ng-formly that is using 'watches' to monitor changes.
I will try to get 'Kent C. Dodds' into the conversation to discuss this topic.For a test. I changed the 'entityAspect' to '$entityAspect' and it did solve the problem.
-
Ward Bell commented
This will **not** happen for two reasons:
1. It would be a profoundly breaking change as `entityAspect` is one of the most widely used properties in the product.
1. **It wouldn't help**. The `entityAspect` is only one of many entity properties that result in circular references and stack overflows. Most navigation properties do it too.
1. The `ng.equal` "deep equality test" is inappropriate for breeze entity comparison as there are just too many values in a typical entity for this to perform well.
1. I don't understand why you'd want that anyway when object reference equality will do for most scenarios I can imagine. Remember that the entity object is mutated in place when breeze updates its values from, say, a re-query or a save.
I urge you to take a different approach to watching a collection of entities. I'd like to know what you're trying to accomplish.
Of course I could be missing something big. It would have to be gigantic for us to even consider such a change.