Share adapter across multiple models


#1

Hi,

I’ve got several RESTAdapters that are exactly the same. Is it possible to share one adapter across multiple models?

I’ve created one super-RESTAdapter that all the others inherit from, but now I’ve got a bunch of empty adapters, which is awful,…

thanks


#2

Can you just create an application adapter? It should cover all models.


#3

I just want the adapter to be used on a certain models, not all of them


#4

Depending on what you’re doing, the methods you’re overriding (e.g. normalizeResponse) could just detect the model based on a whitelist else call this._super instead? Can you share an example?


#5

thanks for a reply

I am overriding methods:

  • shouldReloadAll
  • shouldBackgroundReloadAll
  • shouldReloadRecord
  • shouldBackgroundReloadRecord

my code:

import ApplicationAdapter from './application';

export default ApplicationAdapter.extend({

  findAllPerformed: false,

  shouldReloadAll(store, snapshotRecordArray) {
        //something here
  },
  shouldBackgroundReloadAll(){
    return false;
  },

  shouldReloadRecord(){
    return false;
  },

  shouldBackgroundReloadRecord: function(store, snapshot) {
    return false;
  }
});