Skip to content

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

Description

@jyasskin

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.

Activity

  1. morethanreal commented on Nov 8, 2013

    @morethanreal
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions