Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deepEqual when comparing non Object instantiated objects #2502

Merged
merged 2 commits into from
Mar 27, 2017

Conversation

dmarcos
Copy link
Member

@dmarcos dmarcos commented Mar 18, 2017

Description:

We end up in an infinite loop when a property of the type selector changes value. Two HTML elements are passed through the deepEqual function that runs ad infinitum since each entity references the components that reference the entity itself, that reference the components, that reference the entity...

Changes proposed:
Deep equal only compares deeply if the passed objects are plain JS objects.

@@ -125,10 +125,13 @@ function deepEqual (a, b) {
var keysB;
var valA;
var valB;
var areBothObjects = a && b && a.constructor === Object && b.constructor === Object;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we evaluate these inline so that the if expression can lazy evaluate and possibly not have to do a && b check twice?

@@ -1,5 +1,7 @@
/* global assert, suite, test */
// var entityFactory = require('../helpers').entityFactory;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can keep here


test('avoid deep equal of object that are not instantiated' +
'with the Object constructor in order to avoid infinite loops', function (done) {
var el1 = entityFactory();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just do deepEqual(document.createElement('a-entity'), document.createElement('a-entity'))

@ngokevin ngokevin merged commit fe8df9f into aframevr:master Mar 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants