New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

vuex-module

Package Overview
Dependencies
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vuex-module

Turn vuex modules into poetry.

latest
Source
npmnpm
Version
0.4.0
Version published
Maintainers
2
Created
Source

vuex-module

Module that turns vuex modules into poetry.

Key features

  • Auto namespacing for mutations, actions and getters
  • Mappers for namespaced components
  • Localized state and commit available via this
  • Nicer way of registering mutations, actions and getters
  • Optional global registration for getters

Example

import { VuexModule } from 'vuex-module'
import shop from '../../api/shop'

const { state, getter, action, mutation, build } = new VuexModule('products')

state({ all: [] })

getter(function all() {
  return this.state.all
});

action(function fetch() {
  return shop.getProducts(products => {
    this.commit('fetch', products)
  })
})

mutation(function fetch(products) {
  this.state.all = products
})

export default build()

Getters, actions and mutations will be prefixed with with module name resulting with: products/all, and products/fetch methods.

You can then use VuexModule mappers to map namespaced methods to your components.

export default {
  computed: mapGetters({ products: 'all' }, 'products'),
  methods: mapActions(['fetch'], 'products')
}

Inside mutations state is available via this. This simplifies function declaration and makes code more readable. Same goes for getters and actions (context, commit, rootState, rootGetters).

MIT

Keywords

vue

FAQs

Package last updated on 21 Mar 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts