npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vuex-dry

v0.2.1

Published

DRY vuex, no more repetitive codes

Downloads

150

Readme

Build Status npm version GitHub stars GitHub forks Twitter

WARNING

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.

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.