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-rich-store

v1.1.1

Published

vuex rich store

Downloads

4

Readme

vuex-rich-store

This is the "vuex rich store" you want!

All usable functions

import vuexRichStore, { createMutationsAndActions, createActions, createMutations } from 'vuex-rich-store'

| Functions | Effect | Return | | ------------------------------------ | ---------------------------------------- | -------------------------------------- | | vuexRichStore(richModule) | turn a rich store module to be effective | a common store module | | createMutationsAndActions(options) | create mutations and actions by options | a array contains mutations and actions | | createActions(options) | create actions by options | a array contains actions | | createMutations(options) | create mutations by options | a array contains mutations |

How to simplify vuex module?

WAY 1 : use vuexRichStore

After using with vuexRichStore, your store module will have 5 more optional keys:

  • rich: ( boolean ) a switch to on/off "vuexRichStore"

  • setterList: ( array ) a list of keys to turn to setter mutations/actions

  • setterPrefix: ( string ) the prefix of setter mutation/action, default is "set"

  • toggleList: ( array ) a list of keys to turn to toggle mutations/actions

  • togglePrefix: ( string ) the prefix of toggle mutation/action, default is "toggle"

Notice: the rich to be true is important if you want the rich store module to be effective!

Brfore

module file:

// store/modules/welcome.js

export default {
  namespaced: true,
  state() {
    return {
      text: 'Welcome to Your Vue.js App',
      isShown: false,
    }
  },
  actions: {
    setText({ commit }, payload) {
      commit('setText', payload)
    },
    toggleIsShown({ commit }, payload) {
      commit('toggleIsShown', payload)
    },
  },
  mutations: {
    setText(state, payload) {
      state.value = payload
    },
    toggleIsShown(state, payload) {
      state.isShown = typeof payload === 'boolean' ? payload : !state.isShown
    },
  },
}

index file:

// store/index.js

import welcome from './modules/welcome'

export default {
  ...
  modules: {
    ...
    welcome,
  },
  ...
}

After

module file:

// store/modules/welcome.js

export default {
  namespaced: true,
  rich: true,
  state() {
    return {
      text: 'Welcome to Your Vue.js App',
      isShown: false,
    }
  },
  setterList: ['text'],
  toggleList: ['isShown'],
}

index file:

// store/index.js

import vuexRichStore from 'vuex-rich-store'
import welcome from './modules/welcome'

export default {
  ...
  modules: {
    ...
    welcome: vuexRichStore(welcome),
  },
  ...
}

WAY 2 : use createMutationsAndActions / createActions / createMutations

This way is mostly adapt to the format that Nuxt.js's store modules use.

options

  • setterList: ( array ) same as vuexRichStore's setterList

  • setterPrefix: ( string ) same as vuexRichStore's setterPrefix

  • toggleList: ( array ) same as vuexRichStore's toggleList

  • togglePrefix: ( string ) same as vuexRichStore's togglePrefix

All keys is optional!

Brfore

module file:

// store/modules/movies.js

export const state = () => ({
  list: [],
  pagination: {
    total: 1,
    current: 1,
    pageSize: 10,
  },
})

export const mutations = {
  setList(state, payload) {
    state.list = payload
  },
  setPagination(state, payload) {
    state.pagination = payload
  },
  reset(state) {
    Object.assign(state, state())
  },
}

After

module file:

// store/modules/movies.js

import { createMutations } from 'vuex-rich-store'

export const state = () => ({
  list: [],
  pagination: {
    total: 1,
    current: 1,
    pageSize: 10,
  },
})

const options = {
  setterList: ['list', 'pagination'],
}

export const mutations = {
  ...createMutations(options),
  reset(state) {
    Object.assign(state, state())
  },
}