shop icon indicating copy to clipboard operation
shop copied to clipboard

how to request remote data for category?

Open wilbyang opened this issue 8 years ago • 7 comments

In shop-category-data.html, there is a hard coded categoryList, is is possible to use http get to prepare this data?

wilbyang avatar Aug 28 '17 14:08 wilbyang

Yea what @spyhole said, just remove the hardcoded array, take out value: categoryList, so that you have:

categories: {
  type: Array,
  readOnly: true,
  notify: true
},

then add a constructor with:

constructor() {
  super();
  
  fetch('path/data.json').then(data => data.json()).then(json => {
    this._setCategories(json);
  });
}

jsilvermist avatar Oct 04 '17 13:10 jsilvermist

Im looking to a similar issue, is it possible to fetch the data from firebase real time database? any guidelines?

fabiopalumbo avatar Oct 13 '17 00:10 fabiopalumbo

Can you please help me by pointing out how would you implement pagination? I couldn't find examples with Polymer. So far, I'm trying to change the app-route but I'm not sure it is appropriate

arlejeun avatar Dec 20 '17 19:12 arlejeun

@fabiopalumbo I'm not sure about how the shop would react to real time data changes, but for a simple static parody of the fetch example above but using firebase, you could use something like this:

constructor() {
  super();

  firebase.database().ref('/shop-data/').once('value').then(snapshot => {
    this._setCategories(snapshot.val());
  });
}

jsilvermist avatar Dec 20 '17 20:12 jsilvermist

As far as I know, the Shop app is not supposed to be used in production. It's seems to be just a demo case of the usage of Polymer.

samcarecho avatar Mar 23 '18 15:03 samcarecho

reply https://github.com/Polymer/shop/issues/143#issuecomment-353170407
@jsilvermist Thanks your e.g. It make that request remote data for category be possible. But it's not enough. Because it's request remote data every time when the categories is call. It's make that unable to use offline. I tried to implement a method _getCategories to retrieve data from remote, and I tried to save the Categories data into browser IndexedDB. But only the home page refresh when the first data is retrieved. The /list/ and /detail/ is 404 on the first load.

dravenk avatar Oct 31 '18 03:10 dravenk

    constructor() {
        super();
        this._getCattegory()
    }

    _getCattegory() {
      let that = this;
      setTimeout(function () {
          that.categories = categoryList
      },5000)
    }

    static get properties() { return {

    categoryName: String,

    itemName: String,

    categories: {
      type: Array,
      // value: categoryList,
      // readOnly: true,
      notify: true
    },

If it takes too long to get the categories, crash error

shop-category-data.js:73 Uncaught TypeError: Cannot read property '0' of undefined
  _getCategoryObject(categoryName) {
    for (let i = 0, c; c = this.categories[i]; ++i) {
      if (c.name === categoryName) {
        return c;
      }
    }
  }

this.categories is undefined

dravenk avatar Nov 27 '18 02:11 dravenk