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

Default value for properties doesn't seem to work? #32

Open
mithro opened this issue May 24, 2016 · 2 comments
Open

Default value for properties doesn't seem to work? #32

mithro opened this issue May 24, 2016 · 2 comments

Comments

@mithro
Copy link
Contributor

mithro commented May 24, 2016

For example, for the cz-clock-dash the code does;

    Polymer({
      is: 'cz-clock-dash',

      properties: {
        timezones: {
          type: 'Object',
          notify: true,
          value: function() { return []; }
        }
      },

However, if you leave the "timezone" out of the config.json you end up with the following error on the console;

cz-clock-dash.html:87 Uncaught TypeError: Cannot read property 'forEach' of undefinedPolymer.mutateTimeString @ cz-clock-dash.html:87
Polymer.attached @ cz-clock-dash.html:78
Polymer.Base._addFeature._invokeBehavior @ polymer-micro.html:414
Polymer.Base._addFeature._doBehavior @ polymer-micro.html:409
(anonymous function) @ polymer-micro.html:212
Polymer.RenderStatus.whenReady @ polymer-micro.html:107
Polymer.Base.attachedCallback @ polymer-micro.html:210
Polymer.Base._addFeature.attachedCallback @ polymer-mini.html:105
(anonymous function) @ (index):73l.onload @ polymer.html:1333

Which comes from

      mutateTimeString: function() {
        this.timezones.forEach((timezone, idx) => this.set('timezones.' + idx + '.data', this.currentTimeDay(timezone)));
        this.async(() => this.mutateTimeString(), 1000);
      },

I don't understand polymer to know what is going wrong here. I would have thought that the value method should mean it ends up with a default of an empty list and https://www.polymer-project.org/1.0/docs/devguide/properties kinds of indicates that should be the case?

@shans @dstockwell - Help?

@shans
Copy link
Owner

shans commented May 24, 2016

It's probably just because initial value setting is async. You should ensure that mutateTimeString can deal with this.timezones being undefined.

@mithro
Copy link
Contributor Author

mithro commented May 24, 2016

@shans Why isn't the default value [] and then it get updated when the data is loaded?

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

2 participants