All files / src/utility storeHelpers.js

64.71% Statements 11/17
85% Branches 17/20
100% Functions 5/5
64.71% Lines 11/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50            2x       2x 1x 1x   1x     1x       1x       1x     1x             2x             1x              
import { mapState, mapActions, mapGetters } from 'vuex';
import { has } from 'lodash';
import logger from './logger';
 
export default {
  registerModule(context, name, state) {
    Iif (!context || !name || !state) {
      logger.warn('Context, module name or state is not provided');
      return;
    }
    if (context.$store && context.$store.state && has(context.$store.state, name)) {
      logger.warn(`Module ${name} is already registered`);
      return;
    }
    context.$store.registerModule(name, state);
  },
  unregisterModule(context, name, state) {
    Iif (!context || !name || !state) {
      logger.warn('Context, module name or state is not provided');
      return;
    }
    Iif (!(context.$store && context.$store.state && has(context.$store.state, name))) {
      logger.warn(`Module ${name} is not registered`);
      return;
    }
    context.$store.unregisterModule(name, state);
  },
  mapState(context, moduleName, properties) {
    return mapState.call(
      context,
      moduleName,
      properties,
    );
  },
  mapGetters(context, moduleName, properties) {
    return mapGetters.call(
      context,
      moduleName,
      properties,
    );
  },
  mapActions(context, moduleName, properties) {
    return mapActions.call(
      context,
      moduleName,
      properties,
    );
  },
};