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

support runtime mixins (fixes #895) #1610

Merged
merged 1 commit into from
Aug 3, 2016
Merged

Conversation

ngokevin
Copy link
Member

@ngokevin ngokevin commented Jul 6, 2016

Description:

Support mixins being attached/injected after entities have already loaded.

Changes proposed:

  • When a mixin is attached, find all entities using it that have already loaded, and apply the mixin.
  • Change Component.updateProperties to take an undefined attrValue. This means continue updating properties using mixins and such, but use cached attr value.
  • Rename applyMixin to handleMixinUpdate to signify that it is asynchronous and that it doesn't apply when the mixin is attached. It only handles observed mutations.
  • Rename componentAttrCache to componentCache because after parsing, anything related to the attribute value becomes irrelevant. It becomes purely component data.
  • Various docstrings/comments and max 100-char style stuff.

* For entities that already have been loaded by the time the mixin was attached, tell
* those entities to register the mixin and refresh their component data.
*/
refreshEntities: {
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 use updateEntities to use a consistent language?

cacheAttribute: {
value: function (attr, value) {
var component = components[attr];
if (!component) { return; }
value = value === undefined ? HTMLElement.prototype.getAttribute.call(this, attr) : value;
this.componentAttrCache[attr] = component.parseAttrValueForCache(value);
value = (
Copy link
Member

Choose a reason for hiding this comment

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

What is this parenthesis? Can we collapse to one line?

Copy link
Member Author

Choose a reason for hiding this comment

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

ok. any other comments for this PR?

@@ -326,7 +326,7 @@ module.exports.AAnimation = registerElement('a-animation', {
* Works the same as component mixins but reimplemented because animations
* aren't components.
*/
applyMixin: {
handleMixinUpdate: {
Copy link
Member

Choose a reason for hiding this comment

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

apply mixin seems a better name than handleMixinUpdate. When invoked from the attachedCallback method there's no mixin update anywhere.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I guess so only because of <a-animation>. Otherwise for entities, it's purely a handler for the MutationObserver. I can rename it back for now.


Just to implant the idea in your head, I want to kill <a-animation> for a component-based approach. For timeline and such, I think we could find an API that meshes with ECS. Just bringing this up now because if we didn't have <a-animation>, we could transfer the mixin logic down to the Entity level, and ANode would purely be for load order/events.

Copy link
Member

Choose a reason for hiding this comment

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

We can discuss about removing a-animation. I believe that should be solved by 3rd parties anyways.

@dmarcos dmarcos merged commit 6ab0299 into aframevr:master Aug 3, 2016
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