-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
have setAttribute wait for existing DOM data to init component #2727
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
|
I see the level of a asynchronous a potential problem in the future. Is there any way to make it synchronous? is not calling |
src/core/a-entity.js
Outdated
| if (isDebugMode) { this.components[attrName].flushToDOM(); } | ||
| // Wait for compoent to be initialized with DOM data. | ||
| if (!this.components[attrName] && this.hasAttribute(attrName)) { | ||
| this.addEventListener('componentinitialized', function waitForInit (evt) { |
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 we do?
this.updateComponent(attrName);
this.setAttribute(attrName, arg1);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 would force the initialization of the pending component and then we can set it.
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.
That sort of makes the lifecycle unpredictable. I'd be more comfortable letting things initialize from the normal attachedCallback flow (attachedCallback -> load -> updateComponents), and then try to set. Clear order of init everything first, then run updates.
Forcing an update would change the order of things, and thinking about stuff like dependencies.
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.
Might work. I can try. dependencies doesn't matter since initComponent will set them up. In the case another component depends on it, it's fine to init it a little early.
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.
OK, updated.
| return; | ||
| } | ||
|
|
||
| // Initialize component first if not yet initialized. |
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.
All the real changes are in this clause. The rest was collapsing the indent with an early return.
Description:
(reopened to update GitHub after last outage)
Consider
<a-entity foo bar="a: 10">wherefoodoessetAttribute('bar', {b: 20}). The resulting data should be{a: 10, b: 20}, but the data ends up{b: 20}because thesetAttributetakes over the initialization process and the DOM data gets ignored.Ran into this when I had
raycasterset alinecomponent withstartandend. I was trying to set thecolorandwidthvia HTML, but that data was wiped out.<a-entity raycaster="showLine: true" line="color: red; width: 0.05">.This would have also helped cases where we were setting
dependenciesto satisfy this lifecycle. But that would initialize the component in cases we might not want to (e.g.,raycastermight not always want a line). Before we hadobj-modelset a dependency onmaterialto use its data if defined. We ended up having to remove that.Changes proposed: