Polymer / shop

The Shop app
https://shop.polymer-project.org/
986 stars 494 forks source link

Why isn't the route object configured with default property value? #190

Closed dman777 closed 6 years ago

dman777 commented 6 years ago

How come the route object is not initialized according to documentation? Even if the route is global, shouldn't each element get it's own copy as stated below?

image

shop-app.html

      static get properties() { return {
        page: {
          type: String,
          reflectToAttribute: true,
          observer: '_pageChanged'
        },
        numItems: {
          type: Number,
          value: 0
        },
        _shouldShowTabs: {
          computed: '_computeShouldShowTabs(page, smallScreen)'
        },
        _shouldRenderTabs: {
          computed: '_computeShouldRenderTabs(_shouldShowTabs, loadComplete)'
        },
        _shouldRenderDrawer: {
          computed: '_computeShouldRenderDrawer(smallScreen, loadComplete)'
        }
keanulee commented 6 years ago

Having separate objects is needed when there are multiple instances of the same element (i.e. multiple <shop-app>s) - here there's only ever one <shop-app>. The value of route comes from the two-way bound <app-location> element, so in this case even if there were multiple <shop-app>s each location element will provide its own route object. Although probably good for documentation, it's not necessary to define each property in the static get properties() block.

dman777 commented 6 years ago

thanks