Skip to content

Conversation

@JohnRodney
Copy link
Contributor

Description:
Adds a method to an entity to understand both 'attribute' and 'attribute.property' and returns the appropriate value in either case.
Changes proposed:

  • Remove special casing of circumstances from animation.js
  • Adds native method to element to understand this syntax.
@JohnRodney
Copy link
Contributor Author

@ngokevin I opted to add the functionality to the element to understand the component attribute rather than write more special cases into animation. If you would prefer a different approach please let me know. This is in reference to #1334

@JohnRodney
Copy link
Contributor Author

Hold off on this... even though all the tests work there are visual regressions in the system. Found when going to some examples will dig deeper. A bit strange that all animation tests work when the actual components themselves don't.

@JohnRodney
Copy link
Contributor Author

Hmm the visual regression occurred upstream and not from this PR I will open a new issue.

* @param {string} attr dot notation or singular 'color' or 'material.color'
* @returns {object|string|number} Value of type of component property.
*/
getComputedAttributeFor: {
Copy link
Member

Choose a reason for hiding this comment

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

Might be easier to keep this as a utility function within the animation module for now. (e.g., getComputedAttributeFor(el, attribute).

Not sure if we want to fully support dot notation because if we do it here, then we have to do it for setAttribute as well to be consistent, and it'll increase API surface area / documentation / code to maintain. If we start to see a bigger need for dot notation, then we could re-eval.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This has been updated, but the PR is failing to update on the branch push. Looks like github status at the moment is saying some backend services unavailable. Will recheck when they report servers are running normally.

If the issue doesn't repair I will close and open a new PR.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, GitHub has been acting up last hour.

* @param {string} attr dot notation or singular 'color' or 'material.color'
* @returns {object|string|number} resulting value of type of component property.
*/
function getComputedAttributeFor (el, attribute) {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe name getAttributeWithDotNotation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ngokevin it gets the attribute no matter if it is dot notation or not.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, though it seems the purpose of it is to support dot notation, with fallback. Is that right?

@ngokevin
Copy link
Member

ngokevin commented Apr 5, 2016

Can we add a test for this?

@ngokevin
Copy link
Member

ngokevin commented Apr 5, 2016

Should we add a test that tests the whole animation grabbing the correct from value if using dot notation?

@JohnRodney
Copy link
Contributor Author

Absolutely. The rest of the refactors are addressed other than changing to the function to get with dot notation because it supports both and that name might be misleading?

@ngokevin
Copy link
Member

ngokevin commented Apr 5, 2016

OK, that's fine. I'd emphasize that in the docstring more getComputedAttribute that supports dot notation to look up a component property.

@JohnRodney
Copy link
Contributor Author

Sounds good.

@ngokevin
Copy link
Member

ngokevin commented Apr 5, 2016

Did you see my comment about adding a more integrated test?

@JohnRodney
Copy link
Contributor Author

@ngokevin yea I wanted to see why the last refactor didn't pass the integration test even though it did local before I added another test case. Not sure if this was due to github having issues still so wanted to push the doc refactor first and ensure tests were fine before adding another.

Hmm same issue again, but not occuring on local.

@dmarcos
Copy link
Member

dmarcos commented Apr 6, 2016

I know it's a pain the ass (I'm going through this myself now) but we need to isolate the problem. @JohnRodney Does the failure go away if you comment your test out?

@JohnRodney
Copy link
Contributor Author

JohnRodney commented Apr 6, 2016

@dmarcos sorry didn't get around to trying last night. I had tried to download a different version of firefox so I could get it to fail on my local, but I never got it to. Had to wrap up some other stuff on a project today will be revisiting this again in a few hours and figure it out. As I will need to use an entity generator to get a component to exist on the test.

Is it passing on all tests locally for you as well then failing on travis?

@ngokevin
Copy link
Member

ngokevin commented Apr 7, 2016

Got the tests working #1349

I think the problem is you are creating a scene outside of the setup/teardown. We have global setup methods that expect the scene to be created in a setup handler.

@ngokevin
Copy link
Member

ngokevin commented Apr 7, 2016

You can apply this diff 5bfc71a

@dmarcos
Copy link
Member

dmarcos commented Apr 19, 2016

@JohnRodney What's left to do here?

@JohnRodney
Copy link
Contributor Author

@dmarcos Sorry with all the stuff going on and catching up with work I just haven't had the time to address this. I can close it and re-open after I finish the feature/animateColor PR. Or someone can pick up where I left off here. I know its probably bugging you to have lingering PRs.

@ngokevin
Copy link
Member

I can volunteer to pick this up.

@JohnRodney
Copy link
Contributor Author

@dmarcos I applied the upstream changes here.

This build seems to be failing due to docker not installing from NPM properly. This is a problem with NPM itself and not this branch. npm/npm#9418 (comment)

The problem seems to be intermittent waiting to see if this shows up somewhere else. Or just this branch I could try closing and opening a new PR. Waiting to see what ya'lls suggestions are.

@dmarcos
Copy link
Member

dmarcos commented Apr 29, 2016

@JohnRodney I have restarted the travis build. It seems you need to be an admin of the repo to do it.

@JohnRodney JohnRodney force-pushed the bugfix/componentProperties branch from fe9d51e to 93bf759 Compare April 29, 2016 20:53
if (attributeSplit.length === 1) {
return el.getComputedAttribute(componentName);
}
// If the component exists as an attribute return the property on it
Copy link
Member

Choose a reason for hiding this comment

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

You can declare a variable at the top var attributeValue and do:

attributeValue = el.getComputedAttribute(componentName);
if (attributeValue) { return attributeValue; }
return el.getComputedAttribute(componentPropName);
Copy link
Contributor Author

@JohnRodney JohnRodney Apr 29, 2016

Choose a reason for hiding this comment

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

@dmarcos I may be misunderstanding, but this doesn't work in the case of an attribute needing to be split. We need 3 cases here one for a default, one for a attribute split and then fallback to the native if it doesn't work.

I think I could do:

if (attributeValue) { return attributeValue[componentPropName]; }
return el.getComputedAttribute(componentPropName);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I pushed it up with the example I showed and all tests are working. This should be good.

Copy link
Member

Choose a reason for hiding this comment

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

the code of the whole function I think would be:

function getComputedAttributeFor (el, attribute) {
  var attributeSplit = attribute.split('.'); 
  var attributeValue;
  var componentName = attributeSplit[0]; 
  var componentPropName = attributeSplit[1]; 
  // If the attribute is singular call normal getComputedAttribute function
  if (attributeSplit.length === 1) {
    return el.getComputedAttribute(componentName);
   }
  attributeValue = el.getComputedAttribute(componentName);
  if (attributeValue) { return attributeValue; }
  return el.getComputedAttribute(componentPropName);
}
Copy link
Contributor Author

@JohnRodney JohnRodney Apr 29, 2016

Choose a reason for hiding this comment

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

right but attributeValue would be an object such as in the case of material.color value would be material and the return you need is actually the value of color on material.

The line in question is just:

if (attributeValue) { return attributeValue; }

needing to be

if (attributeValue) { return attributeValue[componentPropName]; }
@dmarcos
Copy link
Member

dmarcos commented Apr 29, 2016

Almost there. Just one more style change.

var componentPropName = attributeSplit[1];
var attributeValue = el.getComputedAttribute(componentName);
// If the attribute is singular call normal getComputedAttribute function
if (attributeSplit.length === 1) {
Copy link
Member

Choose a reason for hiding this comment

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

you can do return attributeValue

@JohnRodney
Copy link
Contributor Author

Cool those adjustments seem solid tests are still good. Ping me if anything else gonna step off for a bit for dinner ect.

@dmarcos
Copy link
Member

dmarcos commented Apr 29, 2016

Nice. Thanks for the patience :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

3 participants