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

website out of date - incorrect arguments to attributeChanged method #419

Closed
BugsNash opened this issue Feb 13, 2014 · 6 comments
Closed
Labels

Comments

@BugsNash
Copy link

In the life cycle methods section of the API reference page, the attributeChanged method is demonstrated with incorrect arguments

attributeChanged: function(attrName, oldVal, newVal) {
//var newVal = this.getAttribute(attrName);
console.log(attrName, 'old: ' + oldVal, 'new:', newVal);
},

In practice, the first argument to this function is oldVal, the second is newVal.

http://www.polymer-project.org/polymer.html#lifecyclemethods

@sjmiles
Copy link
Contributor

sjmiles commented Feb 13, 2014

Afaict, the spec, the polyfill, Polymer source code, and http://jsbin.com/ixIpIMa/5/edit all agree on the call signature.

Do you have a reproduction you can share?

@BugsNash
Copy link
Author

I do, I'll grab it now and send it in a sec. Even later in the same page it
says that the call signature is function(oldValue, newValue):

http://www.polymer-project.org/polymer.html#observeprops

Bugs

On Thu, Feb 13, 2014 at 11:12 AM, Scott J. Miles
[email protected]:

Afaict, the spec, the polyfill, Polymer source code, and
http://jsbin.com/ixIpIMa/5/edit all agree on the call signature.

Do you have a reproduction you can share?


Reply to this email directly or view it on GitHubhttps://github.com//issues/419#issuecomment-34934584
.

@sjmiles
Copy link
Contributor

sjmiles commented Feb 13, 2014

Ah, attribute confusion.

For any observed property, we support a magic method called <property>Changed. If I observe foo then I can make a fooChanged that will be called when the value of foo changes.

This is not to be confused with attributeChanged which is a special method that is called when any attribute is modified on the element.

If you made a property called attribute that could explain the confusion.

@BugsNash
Copy link
Author

aaaaaah ok so attributeChanged is the literal name of a function that is
called whenever any attribute is changed, and Changed is a specialised
method that is called only when property x is changed. I assume this means
that when x xhanges both xChanged and attributeChanged are called?

Bugs

On Thu, Feb 13, 2014 at 11:41 AM, Scott J. Miles
[email protected]:

Ah, attribute confusion.

For any observed property, we support a magic method called
Changed. If I observe foo then I can make a fooChanged that
will be called when the value of foo changes.

This is not to be confused with attributeChanged which is a special
method that is called when any attribute is modified on the element.

If you made a property called attribute that could explain the confusion.


Reply to this email directly or view it on GitHubhttps://github.com//issues/419#issuecomment-34936442
.

@sjmiles
Copy link
Contributor

sjmiles commented Feb 13, 2014

Yes, sorry for the confusion.

It's best to just consider that attributeChanged is called when an attribute changes, and <property>Changed is called when <property> changes.

It's true that properties are sometimes tied to attributes, but not always. Whether a change in a property results in a change in an attribute isn't as obvious as it seems.

The short version is that Polymer tries to be smart about doing the least amount of work it can while keeping your logic correct.

@BugsNash
Copy link
Author

Excellent thanks for the explanation!

Bugs

On Thu, Feb 13, 2014 at 12:00 PM, Scott J. Miles
[email protected]:

Yes, sorry for the confusion.

It's best to just consider that attributeChanged is called when an
attribute changes, and Changed is called when changes.

It's true that properties are sometimes tied to attributes, but not
always. Whether a change in a property results in a change in an attribute
isn't as obvious as it seems.

The short version is that Polymer tries to be smart about doing the least
amount of work it can while keeping your logic correct.


Reply to this email directly or view it on GitHubhttps://github.com//issues/419#issuecomment-34937665
.

@ebidel ebidel added the invalid label Mar 4, 2014
@ebidel ebidel closed this as completed Mar 4, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants