All Projects → abdullah → vuex-module-generator

abdullah / vuex-module-generator

Licence: MIT license
abdullah.github.io/vuex-module-generator

Programming Languages

javascript
184084 projects - #8 most used programming language
Vue
7211 projects
HTML
75241 projects

Projects that are alternatives of or similar to vuex-module-generator

solid-zustand
🐻 State management in Solid using zustand.
Stars: ✭ 44 (-50.56%)
Mutual labels:  state-management
use-app-state
🌏 useAppState() hook. that global version of setState() built on Context.
Stars: ✭ 65 (-26.97%)
Mutual labels:  state-management
use-query-string
🆙 A React hook that serializes state into the URL query string
Stars: ✭ 50 (-43.82%)
Mutual labels:  state-management
wulaphp
一个有点复杂的PHP框架!
Stars: ✭ 26 (-70.79%)
Mutual labels:  module
note
一些技术笔记
Stars: ✭ 174 (+95.51%)
Mutual labels:  module
react-native-tab-navigator
JavaScript for React-Native iOS Android module
Stars: ✭ 35 (-60.67%)
Mutual labels:  module
react-declarative
A React form builder which interacts with a JSON endpoint to generate nested 12-column grids with input fields and automatic state management in a declarative style. Endpoint is typed by TypeScript guards (IntelliSense available). This tool is based on material-ui components, so your application will look beautiful on any device...
Stars: ✭ 17 (-80.9%)
Mutual labels:  state-management
laravel-module
Module management package for Laravel
Stars: ✭ 65 (-26.97%)
Mutual labels:  module
kstatemachine
KStateMachine is a Kotlin DSL library for creating finite state machines (FSM) and hierarchical state machines (HSM).
Stars: ✭ 63 (-29.21%)
Mutual labels:  state-management
aurelia-hoc-store
An Aurelia application showing the use of higher order components and a single state approach.
Stars: ✭ 20 (-77.53%)
Mutual labels:  state-management
google streetview
A command line tool and module for Google Street View Image API
Stars: ✭ 77 (-13.48%)
Mutual labels:  module
PoShLog
🔩 PoShLog is PowerShell cross-platform logging module. It allows you to log structured event data into console, file and much more places easily. It's built upon great C# logging library Serilog - https://serilog.net/
Stars: ✭ 108 (+21.35%)
Mutual labels:  module
concave
🧐 Lens-like state management (for React).
Stars: ✭ 13 (-85.39%)
Mutual labels:  state-management
Framer-CollectionComponent
Framer Module
Stars: ✭ 22 (-75.28%)
Mutual labels:  module
SCF4-SDK
Motorized zoom lens controller Kurokesu SCF4 module featuring STM32 controller and Onsemi LC898201 driver control software
Stars: ✭ 14 (-84.27%)
Mutual labels:  module
react-evoke
Straightforward action-driven state management for straightforward apps built with Suspense
Stars: ✭ 15 (-83.15%)
Mutual labels:  state-management
nuxt-modules
AX2's Nuxt modules
Stars: ✭ 30 (-66.29%)
Mutual labels:  module
store keeper
StoreKeeper is an easy and flexible state management system for Flutter apps
Stars: ✭ 22 (-75.28%)
Mutual labels:  state-management
lovedebug
A fixed and updated repo of LOVEDEBUG
Stars: ✭ 22 (-75.28%)
Mutual labels:  module
UseCases
This a library that offers a generic implementation of the data layers from the clean architecture by Uncle bob.
Stars: ✭ 23 (-74.16%)
Mutual labels:  state-management

Vuex Module Generator (VMG)

VMG allows you to create a vuex module easily.

See All implementations.

See Customer Example.

Supported module types

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

Motivation

Most of the web applications contain CRUD actions. Vuex or other state management libraries like redux implement stores which handle CRUD actions. According 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 states will be changed according to three action types.

  • 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, the developer can use these different states of the module in different cases. For instance, isLoading state can be used by a list to show an indicator or error that can be used to show an error component.

The 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 contain 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 mutations .

Complete example

Note: This example can be used for 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 :)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].