Skip to content

Conversation

@ngokevin
Copy link
Member

@ngokevin ngokevin commented Sep 19, 2016

Description:

I'd expect that getAttribute returns full component data. 99% of the time we're grabbing component data, we want the computed component data, not just what is defined in the attribute. Since everyone knows DOM's getAttribute rather than A-Frame's getComputedAttribute, this is the method they'll reach for first. Since getAttribute currently returns only defined data, it is confusing when el.getAttribute('position') returns null.

Changes proposed:

  • Old getAttribute is now an explicit getDefinedAttribute
  • Old getComputedAttribute is now getAttribute
  • docs
@donmccurdy
Copy link
Member

I like getAttribute having the default behavior of returning full component data: this should make a lot of my code more consistent.

To me getDefinedAttribute() isn't a super-intuitive name for the alternative. Perhaps getShallowAttribute(), getAttributeShallow(), getNonDefaultAttribute(), getAttributeOverrides()? Are there cases when the explicitly overridden subset of properties should be preferred, for performance or something, and if not should it even be exposed?

@ngokevin
Copy link
Member Author

I like getDefinedAttribute because it is getting data from only explicitly defined HTML attributes (either via DOM or setAttribute). Does that clear it up, or do we need more alternatives? At least this method will rarely ever be called in the context of components.

shallow isn't as immediately clear to me (I think of shallow vs. deep object cloning). getNonDefaultAttribute isn't great because the discrepancy not related to default attributes, it is also factoring in mixins. And I don't think setting HTML attributes as overrides.

@dmarcos
Copy link
Member

dmarcos commented Sep 20, 2016

What about getDOMAttribute or getElementAttribute ?

@ngokevin
Copy link
Member Author

They're actually not bad, the only confusion is when you do el.setAttribute('geometry' {primitive: 'box'}), then our new method should return that data, but it is not reflected in the actual DOM nor element. Which is why I liked defined because it takes into account whether defined via DOM or setAttribute.

@donmccurdy
Copy link
Member

Kk, all fine with me.

@dmarcos
Copy link
Member

dmarcos commented Sep 27, 2016

I still think getDefinedAttribute is a very cryptic name. getElementAttribute and getDOMAttribute are more explicit. They might be inconsistent if you look at the DOM inspector but I expect that use case to become more and more rare as people transition to the inspector.

@ngokevin
Copy link
Member Author

updated

@dmarcos dmarcos merged commit eb1b7a5 into aframevr:master Sep 28, 2016
jesstelford added a commit to jesstelford/aframe-keyboard-controls that referenced this pull request Nov 20, 2016
Latest aframe (`master`) deprecated `getComputedAttribute`, and replaced it with the more intuitive `getAttribute`.

More info: aframevr/aframe#1925
jesstelford added a commit to jesstelford/aframe-physics-system that referenced this pull request Nov 20, 2016
Latest aframe (`master`) deprecated `getComputedAttribute`,
and replaced it with the more intuitive `getAttribute`.

More info: aframevr/aframe#1925
donmccurdy pushed a commit to donmccurdy/aframe-keyboard-controls that referenced this pull request Nov 20, 2016
Latest aframe (`master`) deprecated `getComputedAttribute`, and replaced it with the more intuitive `getAttribute`.

More info: aframevr/aframe#1925
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

3 participants