MCPcopy Index your code
hub / github.com/abdullah/vuex-module-generator

github.com/abdullah/vuex-module-generator @v1.0.4

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.0.4 ↗ · + Follow
90 symbols 181 edges 52 files 0 documented · 0% updated 6y ago★ 89
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Vuex Module Generator (VMG)

VMG allows you to create a vuex module easly,

See All examples

Supported module types

  • Clone
  • Crud
  • Export
  • Import
  • Move
  • Sort

Motivation

Most of web applications contains CRUD actions. Vuex or other state management libraries like redux implement stores which handle CRUD actions. Acording to some store patterns each module must contain isLoading, isLoaded, data and errors properties in own state therefore a module's state can be implemented like this;

const customerState = {
  list: {
    isLoading: false,
    isLoaded: false,
    data: [],
    errors: {}
  }
};

Sure, there must be other module members type,actions and mutations. Check completed vuex module according to module pattern.

This module contains list state with isLoading, isLoaded, data and errors properties. When fetchCustomer action is called, these state will be changed according to three action type.

  • INDEX.REQUEST, it sets isLoading true, this means list has been being fetching
  • INDEX.SUCCESS, it sets isLoading false, isLoaded true and data with payload.data, this means list has been fetched and there is no problem when it was happening
  • INDEX.FAILURE, it sets isLoading false, isLoaded false, data: empty array (b/c it is a list), this means there is an error and it was failed

Finally, developer can use these different states of module in different cases. For instance isLoading state can be used by a list to show an indicator or error can be used to show an error component.

Purpose of VMG is reducing code lines and making development easy.

Use cases

If you have a large application which contains CRUD actions in each page/module/component. If you want to control async states. If you want to set a rule which limits to do CRUD actions.

Usage

Import generator members.

import { createCrudActions, createCrudActionTypes, createCrudMutation, createCrudState } from 'vuex-module-generator';

createCrudState returns an object which contains list, active, creating, updating, destroying properties. These properties contains some sub properties. Check CRUD state .

createCrudActions returns CRUD methods to manage index, show, create etc. resource. Check CRUD actions .

createCrudActionTypes returns action types which will be used by createCrudActions.

createCrudMutation return functions which handle CRUD state mutations. Check CRUD actions .

Complete example

Note : This example can be used other VMG members.

/* eslint-disable no-param-reassign */
import { createCrudActions, createCrudActionTypes, createCrudMutation, createCrudState } from 'vuex-module-generator';

export const types = {
  ...createCrudActionTypes('MODULE_NAME')
};

export const actions = createCrudActions(types);

export default {
  state: { ...createCrudState() },
  mutations: { ...createCrudMutation(types) },
  actions: {
    async fetchSomeResource({ commit }) {
      commit(actions.index.request());
      try {
        const res = await asyncSomeResourceAction();
        const { data, meta } = res.data;
        commit(actions.index.success({ data }));
        return { data, meta };
      } catch (error) {
        commit(actions.index.failure(error));
        return Promise.reject(error);
      }
    }
  }
};

Credit

Thanks Altay Aydemir, he was my previous developer which wrote this factory for redux, I have implemented it for vuex. That's all :)

Core symbols most depended-on inside this repo

createAction
called by 39
src/action/plain.js
createAsyncActionType
called by 10
src/type/async.js
createCrudActionTypes
called by 5
src/type/crud.js
createCrudActions
called by 4
src/action/crud.js
createImportActionTypes
called by 4
src/type/import.js
createMoveActionTypes
called by 4
src/type/move.js
createSortActionTypes
called by 4
src/type/sort.js
createExportActionTypes
called by 4
src/type/export.js

Shape

Function 90

Languages

TypeScript100%

Modules by API surface

src/mutations/crud.js22 symbols
examples/crud.js7 symbols
examples/async.js5 symbols
src/mutations/sort.js4 symbols
src/mutations/move.js4 symbols
src/mutations/import.js4 symbols
src/mutations/export.js4 symbols
src/mutations/clone.js4 symbols
docs/example-module.js4 symbols
examples/sort.js2 symbols
examples/move.js2 symbols
examples/import.js2 symbols

For agents

$ claude mcp add vuex-module-generator \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page