-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Store oldData after building component data. undefined passed to upda… #2840
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
Conversation
|
Can we avoid making oldData undefined on the first call? It's extra work to check and opens up for potential for lots of bugs in components (e.g., not accounting it could be both undefined or an object). Can we separate the internal old data versus the public one? |
|
Old Data being undefined it what makes sense to me? What do you pass to update on first call, when the component has been just initialized? |
|
Empty data makes just as much sense. And it's backwards incompatible and puts less type checking effort and less potential bugs for component authors. What do we return where? |
|
What about components that don't have an object as schema data type like visible for instance? If the default is false people might do things like |
|
undefined works better for single-prop schemas. I think that was the current behavior. |
|
Ok, I'll revert back to passing |
71645a7 to
f0f6ff6
Compare
ngokevin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r+wc
| var isSinglePropSchema; | ||
| var oldData; | ||
| var skipTypeChecking; | ||
| var oldData = this.oldData; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can initialize this in the component constructor as undefined.
src/core/component.js
Outdated
| delete el.initializingComponents[this.name]; | ||
| // Play the component if the entity is playing. | ||
| // We pass empty object to multiple property schemas and single property schemas that parse to objects like position, rotation, scale | ||
| // undefined is passed to the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment stopped suddenly
| this.update(oldData); | ||
| // Play the component if the entity is playing. | ||
| if (el.isPlaying) { this.play(); } | ||
| this.oldData = extendProperties({}, this.data, isSinglePropSchema); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Store current data as previous data for future updates.
| if (!skipTypeChecking && utils.deepEqual(oldData, this.data)) { return; } | ||
| if (!skipTypeChecking && utils.deepEqual(this.oldData, this.data)) { return; } | ||
|
|
||
| this.oldData = extendProperties({}, this.data, isSinglePropSchema); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Store current data as previous data for future updates.
| // 1. Default values (lowest precendence). | ||
| if (isSinglePropSchema) { | ||
| data = schema.default; | ||
| data = typeof schema.default === 'object' ? utils.extend({}, schema.default) : schema.default; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clone default value if object so components don't share object.
|
Can also update the PR description for future reference. |
…te on component initialization (fix aframevr#2829)
handle undefined oldData initially (fixes side effect of aframevr/aframe#2840)
|
Is there going to be a 0.6.1 patch release for this bug fix? |
|
yeah |
handle undefined oldData initially (fixes side effect of aframevr/aframe#2840)
…te on component initialization (fix #2829)
The following call to
getAttributereturns the data object of the component (this happens due to one of the perf optimization to reduce unnecessary object copies) that gets modified and then passed to thesetAttributemethod.the oldData object was constructed before building the data object resulting in the oldData to actually contain the current data. The condition that checks if the component should be updated (oldData !== data) was failing because the objects were identical.
Two fundamental changes in this PR: