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

Attribute values should be copied to property values before created #342

Closed
jyasskin opened this issue Nov 8, 2013 · 1 comment
Closed

Comments

@jyasskin
Copy link

jyasskin commented Nov 8, 2013

This document

<!DOCTYPE html>
<html>
<head>
<script src="polymer.min.js"></script>
<polymer-element name="my-lifecycle" attributes="foo">
  <script>
    Polymer('my-lifecycle', {
      created: function() {
        console.log('created', this.foo);
      },
      ready: function() {
        console.log('ready', this.foo);
      },
    });
  </script>
</polymer-element>
</head>
<body>
<my-lifecycle foo="bar"></my-lifecycle>
</body>
</html>

produces a console log of:

created null
ready bar

which surprised me, and doesn't seem to be implied by http://www.polymer-project.org/polymer.html#configuring-an-element-via-attributes or http://www.polymer-project.org/polymer.html#lifecyclemethods. This could just be a documentation issue, but created seems like the place to "configure" an element, so it seems like the attributes should be propagated in at this point rather than waiting until ready.

@morethanreal
Copy link
Contributor

Generally element initialization code should be called from ready. created corresponds to createdCallback from the spec. This is the first callback an element receives and Polymer sets up data binding, property observers, Shadow DOM, etc. for the element at this time, which is why the attributes are not reflected to the properties at created time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants