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-alt

v0.0.8

Published

An alternative approach to Vuex helpers for accessing state, getters and actions that doesn't rely on string constants.

Downloads

104

Readme

Vuex-Alt

An alternative, opinionated approach to Vuex helpers for accessing state, getters and actions that doesn't rely on string constants.

Installation

First install the npm package with

npm install --save vuex-alt

Then use the plugin, passing in the Vuex Store.

import Vuex from 'vuex';
import { VuexAltPlugin } from 'vuex-alt';

// use Vuex as usual
Vue.use(Vuex);

// create your store
const store = new Vuex.Store({ ... });

// use the VuexAltPlugin, and pass it
// the new Vuex Store
Vue.use(VuexAltPlugin, { store });

Prerequisites

Vuex-Alt makes two intentional, opinionated assumptions about your Vuex code:

  1. Mutations are only commited from within actions. Components never directly commit mutations. Every mutation has an accompanying action.
  2. All Vuex state, getters and actions are organized into Vuex modules.

These two rules lead to more scalable state management code, and more predictable state changes.

API Usage

Vuex-Alt provides an alternative approach to the Vuex helpers for mapState, mapActions, and mapGetters.

The main difference between the Vuex-Alt helpers and the original Vuex helpers is that instead of accepting strings to specify the namespace and action/getter you want, access is done via functions and nested objects.

mapState()

Provide an object that maps local Vuex instance properties to Vuex module properties.

For example, if you have a state property called count on a Vuex store module called counter you would access it like this:

computed: {
  ...mapState({
    count: (state) => state.counter.count
  })
}

mapActions()

Provide an object that maps local Vuex instance methods to Vuex module methods.

For example, if you have an action called increment() on a Vuex store module called counter you would access it like this:

methods: {
  ...mapActions({
    increment: (actions) => actions.counter.increment
  })
}

Now you can access it in your component via this.increment(10).

mapGetters()

Provide an object that maps local Vuex instance properties to Vuex module getters.

For example, if you have a getter called countPlusTen() on a Vuex store module called counter you would access it like this:

computed: {
  ...mapGetters({
    countPlusTen: (getters) => getters.counter.countPlusTen
  })
}