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

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

Closed
ebidel opened this issue Apr 2, 2015 · 3 comments
Closed
Labels

Comments

@ebidel
Copy link
Contributor

ebidel commented Apr 2, 2015

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
    }
});
@ebidel ebidel added the 0.8 label Apr 2, 2015
@sorvell
Copy link
Contributor

sorvell commented Apr 3, 2015

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

observers: {
  'key published': 'doStuff'
}

@ebidel
Copy link
Contributor Author

ebidel commented Apr 5, 2015

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.

@sorvell
Copy link
Contributor

sorvell commented Apr 6, 2015

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).

@sorvell sorvell closed this as completed May 22, 2015
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

2 participants