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

how to request remote data for category? #143

Open
wilbyang opened this issue Aug 28, 2017 · 7 comments
Open

how to request remote data for category? #143

wilbyang opened this issue Aug 28, 2017 · 7 comments
Labels

Comments

@wilbyang
Copy link

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

@jsilvermist
Copy link

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);
  });
}

@fabiopalumbo
Copy link

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

@arlejeun
Copy link

arlejeun commented Dec 20, 2017

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

@jsilvermist
Copy link

@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());
  });
}

@samcarecho
Copy link

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.

@dravenk
Copy link

dravenk commented Oct 31, 2018

reply #143 (comment)
@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
Copy link

dravenk commented Nov 27, 2018

    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

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

7 participants