superwf / vuex-cache

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

store.cache.dispatch throws an error if payload have circular references #29

Closed VitorLuizC closed 5 years ago

VitorLuizC commented 5 years ago

If you pass a payload with circular references to store.cache.dispatch it throws TypeError: Converting circular structure to JSON.

This can be checked by running the code below.

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

Vue.use(Vuex);

const store = new Store({
  plugins: [
    cache({})
  ],
  actions: {
    show(_, value) {
      console.log(value);
    }
  }
});

const a = {}, b = {};

a.b = b;
b.a = a;

store.cache.dispatch('show', a); // It throws an error.

See by yourself on CodeSandbox.

@superwf vuex-cache uses JSON.stringify and it carries its limitations. So I propose fallback to uncached action instead of just throws Error.