How to use the @ember-data/store.extend function in @ember-data/store

To help you get started, we’ve selected a few @ember-data/store examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hashicorp / vault / ui / app / services / store.js View on Github external
}

export function keyForCache(query) {
  /*eslint no-unused-vars: ["error", { "ignoreRestSiblings": true }]*/
  // we want to ignore size, page, responsePath, and pageFilter in the cacheKey
  const { size, page, responsePath, pageFilter, ...queryForCache } = query;
  const cacheKeyObject = Object.keys(queryForCache)
    .sort()
    .reduce((result, key) => {
      result[key] = queryForCache[key];
      return result;
    }, {});
  return JSON.stringify(cacheKeyObject);
}

export default Store.extend({
  // this is a map of map that stores the caches
  lazyCaches: computed(function() {
    return new Map();
  }),

  setLazyCacheForModel(modelName, key, value) {
    const cacheKey = keyForCache(key);
    const cache = this.lazyCacheForModel(modelName) || new Map();
    cache.set(cacheKey, value);
    const lazyCaches = this.lazyCaches;
    const modelKey = normalizeModelName(modelName);
    lazyCaches.set(modelKey, cache);
  },

  getLazyCacheForModel(modelName, key) {
    const cacheKey = keyForCache(key);