vuex-getters-warning-plugin

A plugin for Vuex which dumps warning when accessing to non-existent getters.
2,599
Install
npm install vuex-getters-warning-plugin
Latest Version:1.1.3
Vue:2
License:MIT
Last Updated:Jan 3, 2023
Links: GitHub  ·  npm
Maintainer: ymmooot

vuex-getters-warning-plugin

CircleCI version

A plugin for Vuex which dumps warning when accessing to non-existent getters.

Usage

import getterWarning from 'vuex-getters-warning-plugin';

const store = new Vuex.Store({
  plugins: [getterWarning()],
  state: {
    name: 'Alice',
  },
  getters: {
    nameWithHonorific(state) {
      return `Ms. ${state.name}`;
    },
  },
});

Once registerd it, you will get warning in the console when accessing to non-exsistent getters.

const age = vm.$store.getters.age;
// A nonexistent getter has been called: age

Options

logger Function

You can specify the logger called on warning. The logger receives the two arguments, a static message from this plugin and the called target key.

// even throw an error

const store = new Vuex.Store({
  plugins: [getterWarning({
    logger: (...args) => { throw new Error(args.join(' ')) },
  })],
  state: {
    name: 'Alice',
  },
  getters: {
    nameWithHonorific(state) {
      return `Ms. ${state.name}`;
    },
  },
});

const age = vm.$store.getters.age;
// Error: A nonexistent getter has been called: age

default: console.warn

silent Boolean

This can prevent installing this plugin.

const store = new Vuex.Store({
  plugins: [getterWarning({
    silent: process.env.NODE_ENV === 'production',
  })],
  state: {
    name: 'Alice',
  },
  getters: {
    nameWithHonorific(state) {
      return `Ms. ${state.name}`;
    },
  },
});

const age = vm.$store.getters.age;
// nothing dumps.

default: process.env.NODE_ENV === 'production'

Version History

Version Released Vue License
1.1.3 ^2.6.9 MIT
1.1.2 ^2.6.9 MIT
1.1.1 ^2.6.9 MIT
1.1.0 ^2.6.9 MIT
1.0.0 ^2.6.9 MIT