All Projects → ktsn → vuex-strong-cache

ktsn / vuex-strong-cache

Licence: MIT license
Allow stronger cache for Vuex getters

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

vuex-strong-cache

Allow stronger cache for Vuex getters.

What is this?

This library allows you to cache the result of function that returned by a getter. In other words, even if you write like the following getter, the final result will be cached as same as a normal getter result.

getters: {
  getTodoById: (state, getters) => (id) => {
    return state.todos.find(todo => todo.id === id)
  }
}

Installation

$ npm install --save vuex-strong-cache
# or
$ yarn add vuex-strong-cache

Usage

vuex-strong-cache provides a helper function that can enhance getters. You can just wrap your getters by the enhancedGetters helper so that all your getters will ready to have stronger caching.

import { enhancedGetters } from 'vuex-strong-cache'

export default {
  state: {
    todos: []
  },

  getters: enhancedGetters({
    getTodoById: (state, getters) => (id) => {
      return state.todos.find(todo => todo.id === id)
    }
  }),

  // ...
}

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].