jeudi 20 avril 2017

Custom query function for Ember Data adapter

I'm trying to override my default query function in my application adapter. I'm using query to get data from the backend, when the application goes offline I'd like to query only the data currently stored in the cache, in the style of .peekAll().

This is what I have so far.

// adapters/application.js
  
// turns to cache when no connection available
export default DS.JSONAPIAdapter.extend({
  // ...
  query(store, type, query) {
    let isOnline = this.get('isOnline'); // updates according to connection, returns true or false
    return isOnline ? store.query(type, query) : store.filter(type, query);
  }
}

but my problem is I'm not able to execute the query function within the query function properly. Not sure what's the problem here, I tried wrapping this in promises or returning with .then().

// can't get this to work
query(store, type, query) {
    return store.query(type, query);
}

I feel like once I get that right, the rest won't be much of a problem.

Any help, ideas or workarounds much appreciated!




Aucun commentaire:

Enregistrer un commentaire