superwf / vuex-cache

cache vuex action when dispatch
MIT License
510 stars 32 forks source link

FEATURE: Set default timeout value #11

Closed hvaughan3 closed 6 years ago

hvaughan3 commented 6 years ago

I like the new timeout feature. It would be nice if we could set a default timeout while still being able to give a timeout per dispatch as well. Perhaps it could be passed into the constructor when the plugin is initialized:

import Vuex from 'vuex'
import vuexCache from 'vuex-cache'
const store = new Vuex.Store({
  state: {
    ...
  },

  plugins: [vuexCache(DEFAULT_TIMEOUT_VALUE_HERE)],

  mutations: {
    ...
  },

  actions: {
    ...
  }
})
VitorLuizC commented 6 years ago

This is a nice suggestion!

@superwf it'll cause a breaking change, but seems really nice. A options object (optional) would be better than just the timeout, since we can attach other options to it in the future.

Example

import Vuex, { Store } from 'vuex';
import cache from 'vuex-cache';

const store = new Store({
  plugins: [
    cache({ timeout: 10000 })
  ]
})
hvaughan3 commented 6 years ago

Yea that makes more sense for sure. Thanks.

superwf commented 6 years ago

feature added, try a test?

hvaughan3 commented 6 years ago

@superwf Seems to work great! Thanks so much for the quick implementation.