All Projects → eunjae-lee → vuex-dry

eunjae-lee / vuex-dry

Licence: MIT license
[NO LONGER MAINTAINED] `vuex-dry` helps keep your vuex codes DRY.

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to vuex-dry

immutable-cursor
👊 Immutable cursors incorporating the Immutable.js interface over a Clojure-inspired atom
Stars: ✭ 58 (+5.45%)
Mutual labels:  state-management
trux
Unidirectional data layer for reactive user interfaces
Stars: ✭ 59 (+7.27%)
Mutual labels:  state-management
react-immer
No nonsense state management with Immer and React hooks
Stars: ✭ 13 (-76.36%)
Mutual labels:  state-management
query-param-store
Angular Reactive Query Parameters Store
Stars: ✭ 15 (-72.73%)
Mutual labels:  state-management
rex-state
Convert hooks into shared states between React components
Stars: ✭ 32 (-41.82%)
Mutual labels:  state-management
temperjs
State management for React, made simple.
Stars: ✭ 15 (-72.73%)
Mutual labels:  state-management
hoox
Functional react state management base on hooks
Stars: ✭ 80 (+45.45%)
Mutual labels:  state-management
react-mlyn
react bindings to mlyn
Stars: ✭ 19 (-65.45%)
Mutual labels:  state-management
redux-interactions
Composing UI as a set of interactions
Stars: ✭ 22 (-60%)
Mutual labels:  state-management
devon4flutter-non-bloc-arch
A guide aiming to bridge the gap between the absolute Flutter basics and clean, structured Flutter Development
Stars: ✭ 283 (+414.55%)
Mutual labels:  state-management
unstated
Simple state management for react
Stars: ✭ 12 (-78.18%)
Mutual labels:  state-management
hami-vuex
🍈 Hami melon flavored Vuex, modular by design, completely TypeScript intelligence, state management for Vue.js.
Stars: ✭ 19 (-65.45%)
Mutual labels:  state-management
space-state
Demo app for Subjecting State to Good Behavior
Stars: ✭ 46 (-16.36%)
Mutual labels:  state-management
flutter super state
A simple super state management library for Flutter (with async support)
Stars: ✭ 22 (-60%)
Mutual labels:  state-management
ReduxSimple
Simple Stupid Redux Store using Reactive Extensions
Stars: ✭ 119 (+116.36%)
Mutual labels:  state-management
UniTEA
Implementation of The Elm Architecture for Unity3D
Stars: ✭ 31 (-43.64%)
Mutual labels:  state-management
lit-state
Simple shared app state management for LitElement.
Stars: ✭ 93 (+69.09%)
Mutual labels:  state-management
niue
A tiny shared state and event library for React
Stars: ✭ 17 (-69.09%)
Mutual labels:  state-management
vue-reactive-store
A VueX alternative : declarative + reactive + centralized way to structure your data store. Inspired by VueX and Vue.js . Compatible with vue-devtools.
Stars: ✭ 27 (-50.91%)
Mutual labels:  state-management
xstate.dart
xstate for dart & flutter
Stars: ✭ 31 (-43.64%)
Mutual labels:  state-management

Build Status npm version GitHub stars GitHub forks Twitter

NO LONGER MAINTAINED

This repository is not actively maintained. I haven't used this package for a year. It means there has been no change.

You can still use this as long as it works in your environment. I do not guarantee it works with Vue 3.

You may want to check out another libraries like pinia

Introduction

vuex-dry helps keep your vuex code DRY. It doesn't introduce any whole new way to use vuex. It just helps build modules for you with a minimum amount of code, adding some convenient getters, mutations, and actions.

vuex-dry is TypeScript-friendly since it's written in TypeScript.

Install

npm i vuex-dry -S

Add the plugin to your vuex store.

import { plugin } from "vuex-dry";

new Vuex.Store({
  plugins: [plugin],
  ...
});

Getting Started

Simple Module

import { Module } from "vuex-dry";

const user = Module.build({
  state() {
    return {
      name: undefined
    };
  }
});

const store = new Vuex.Store({
  modules: {
    user
  }
});

That's it. At Module.build(), we put a function named state returning an object. This object will be used as an initial state and also used when you want to reset a specific state or even whole state. We'll see how to reset things later.

Let's look at the module building part again.

Module.build({
  state() {
    return {
      name: undefined
    };
  }
});

The code above is effectively same as the following:

{
  namespaced: true,
  state {
    name: undefined
  },
  getters: {
    name: state => state.name
  },
  mutations: {
    name$assign(state, value) {
      state.name = value;
    },
    name$reset(state) {
      state.name = undefined;
    },
    $resetAll(state) {
      state.name = undefined;
      // also resetting other states if exists
    }
  },
  actions: {
    name$assign({ commit }, value) {
      commit("name$assign", value);
    },
    name$reset({ commit }) {
      commit("name$reset");
    },
    $resetAll({ commit }) {
      commit("$resetAll");
    }
  }
})

You see what has been done here?

The followings are added to your module:

  • A getter name
  • A mutation and an action name$assign to set a value to the state name.
  • A mutation and an action name$reset to reset the state name.
  • A mutation and an action $resetAll to reset all states from the module.

These are always repeated every time we write vuex code. And now you don't need them anymore.

Interested?

Let me show you how easy you can access/handle arrays and objects with vuex-dry.

And you will see how to map those getters in your component and you even can map a specific nested property of an object.

➡️ READ THE FULL DOCUMENT📜 (It will probably take only 3 minutes)

So, why vuex-dry?

It keeps your code DRY. You don't have to write meaningless similar codes over and over again.

Then why not vuex-pathify?

vuex-pathify is a great library. It let you do things without any coding but just with conventions. A downside is it introduces its own conventions and once you get started with it, you're in a whole new thing. On some level, you're using vuex through APIs of vuex-pathify, but on the outside you actually are not using vuex anymore.

On the other hand, vuex-dry just simply creates vuex modules and they are completely compatible with your existing vuex store and modules. And since it's creating pure vuex modules, you can extend it as you want. It's highly customizable. In that sense, it's really easy to introduce vuex-dry into your current project and you don't even have to replace all your vuex codes with vuex-dry. You can partially adjust vuex-dry and there's no problem with that.

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Author

Eunjae Lee, Released under the MIT License.

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].