shans / chromez

Apache License 2.0
2 stars 18 forks source link

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

Open mithro opened 8 years ago

mithro commented 8 years ago

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 commented 8 years ago

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

mithro commented 8 years ago

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