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

v1.3.4

Published

Support custtom util in Vuex action

Downloads

251

Readme

intro

Vuex Keg

A container plugin for Vuex\

LICENSE IMAGE FOSSA Status Build Status Codecov npm

Using Redux? see redux-keg (working on it)

$ npm i -S vuex-keg

$ yarn add vuex-keg

Vuex Keg plugins

Why Do I Need This?

Vuex context has only {dispatch, commit, state, getters, rootState, rootGetters}
Vuex-keg is a solution to add more your functions for vuex

Why Should I Add More functions?

You may need a function to process repetitive code.

const actions = {
  myAction({commit, dispatch}, payload){
    if(payload === 'tree'){
      // do1, do2, ...
    }
    if(payload === 'sky'){
      // do1 
      commit(payload)
    }
    // ...
    dispatch('more thee')
  },
  myAction2({commit}){
    if(payload === 'tree'){
      // do1, do2, ...
    }
    if(payload === 'sky'){
      // do1 
      commit(payload)
    }
     commit('tree')
  }
}

Why don't you make and add a function for it

import {keg} from './src' 
const action = {
  ...keg({
    myAction({commit, dispatch, myUtil}, payload){
      myUtil()
      dispatch('more thee')
    },
    myAction2({commit, myUtil}, payload){
      myUtil()
      commit('tree')
    }
  })
}

How to Register & Use

import Vue from 'vue'
import Vuex from 'vuex'
import VuexKeg, {keg} from './'
Vue.use(Vuex)
const store = new Vuex.Store({
    state: {
      count: 0,
    },
    mutation: {
      increase(state) {
        state.count += 1
      },
    },
    actions: {
      IAmJustAnAction({commit}, payload) {
        commit('increase')
      },
      // support single running by the name parameter
      // no need the name if you think you don't need to use context.name in plugins of Vuex-keg
      doSayHum: keg(({justSay}, payload) => {
        justSay('Hum', 'foo')
      }, {}, 'doSayHum'),
      // Now Keg can set many actions at once
      ...keg({
        doSayHi({justSay, commit}, payload) {
          // custom keg util
          justSay('Hi', 'foo')
          // do mutation
          commit('increase')
        },
        doSayHo: ({justSay, commit}, payload) => {
          // custom keg util
          justSay('Ho', 'foo')
          // do mutation
          commit('increase')
        },
        doSayHa: ({justSay, commit}, payload) => {
          // custom keg util
          justSay('Ha', 'foo')
          // do mutation
          commit('increase')
        },
      }, {
         pluginOptions: {
           justSay: 'anyOptions' // now Keg can send options for plugins
         }
      }),
      // now Keg can hook before and after the Action is executed [^1.2.1]
      ...keg({
        hookTest: (context, payload) => {
          console.log(payload) // 'brforeHook/[payload]'
          return payload
        } // action result is 'afterHook/brforeHook/[payload]'
      }, {
        // shouldHave: ... // ignore except/ only options
        beforeHook: ['beforeHook', (context, payload) => (payload)], // it can be array, which will run all plugins in order
        afterHook: 'afterHook', // can be string
      })
    },
    plugins: [
      VuexKeg({
        plugins: {
          justSay: (store) => (context, payload, options) => (say, yourName) => (window.console.log(`${say}!`, yourName, options)),
          beforeHook: (store) => (context, payload) => (param /*payload*/) => (`beforeHook/${param}`),
          afterHook: (store) => (context, payload) => (param /*result*/) => (`afterHook/${param}`)
        },
        // beforeAction: ...
        // afterAction: ...
      })
    ],
  }
)