Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

store.cache.dispatch treat falsy values as undefined #30

Closed
VitorLuizC opened this issue Feb 23, 2019 · 0 comments
Closed

store.cache.dispatch treat falsy values as undefined #30

VitorLuizC opened this issue Feb 23, 2019 · 0 comments
Labels

Comments

@VitorLuizC
Copy link
Collaborator

The argsToString function ignore falsy values.

vuex-cache/src/index.js

Lines 10 to 12 in 637815b

if (args[1]) {
type = `${type}:${toString(args[1])}`
}

We shouldn't ignore any value, even undefined should be used to generate cache's key.

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: {
    hi(_, payload) {
      console.log('Hi', payload);
    }
  }
});

store.cache.dispatch('hi', undefined); // It shows 'Hi undefined'

store.cache.dispatch('hi', null); // It don't show anything

store.cache.dispatch('hi', 0); // It don't show anything

store.cache.dispatch('hi', ''); // It don't show anything

store.cache.dispatch('hi', NaN); // It don't show anything

store.cache.dispatch('hi', false); // It don't show anything

See by yourself on CodeSandbox.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant