Skip to content

[0.8] - default property values are not set by the time observers are called #1364

Description

@ebidel

In this example, I'm seeing this.published === undefined in keyChanged. I'd expect all of the element's properties to have their default values by the time keyChanged is called:

Polymer({
    is: 'google-sheets',
    properties: {
      key: {
        type: String,
        value: '',
        observer: 'keyChanged'
      },
      published: {
        type: Boolean,
        value: false
      }
    },

    keyChanged: function(newValue, oldValue) {
      //this.published === undefined when the element loads
    }
});

Activity

  1. sorvell commented on Apr 3, 2015

    @sorvell
    Contributor

    You cannot depend on the value of one property in the observer of another. Instead consider this:

    observers: {
      'key published': 'doStuff'
    }
    
  2. ebidel commented on Apr 5, 2015

    @ebidel
    ContributorAuthor

    Thanks @sorvell. So is this the recommended pattern now? I also want to react to individual properties changing later on.

    @arthurevans I think we can be more precise in the section on observers. What's not clear:

    1. When does the callback get called? end of micro task?
    2. If any of the properties change, the callback gets called. People could think they all have to change.
  3. sorvell commented on Apr 6, 2015

    @sorvell
    Contributor

    So is this
    https://github.com/Polymer/core-ajax/blob/0.8-preview/core-ajax.html#L308-L311 the
    recommended pattern now?

    Yes, but this is an area we're still refining so it may change slightly in
    the 0.9 timeframe.

    When does the callback get called? end of micro task?

    Yes

    If any of the properties change, the callback gets called. People could
    think they all have to change.

    Yes

    On Sun, Apr 5, 2015 at 9:40 AM, Eric Bidelman notifications@github.com
    wrote:

    Thanks @sorvell https://github.com/sorvell. So is this
    https://github.com/Polymer/core-ajax/blob/0.8-preview/core-ajax.html#L308-L311
    the recommended pattern now? I also want to react to individual properties
    changing later on.

    @arthurevans https://github.com/arthurevans I think we can be more
    precise in the section on observers
    https://www.polymer-project.org/0.8/docs/devguide/properties.html#observing-changes-to-multiple-properties.
    What's not clear:

    1. When does the callback get called? end of micro task?
    2. If any of the properties change, the callback gets called. People
      could think they all have to change.

    —
    Reply to this email directly or view it on GitHub
    #1364 (comment).

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions