vuex-subscriptions

1.1.0 • Public • Published

vuex-subscriptions

Subscribe to Vuex mutations

npm

Requirements

Installation

Using Yarn

$ yarn add vuex-subscriptions

Or NPM

$ npm install vuex-subscriptions

Usage

import addSubscriptions from 'vuex-subscriptions'
 
const modules = {
    // Modules
}
 
const store = new Vuex.Store({
  // ...
  plugins: [
   addSubscriptions({
   subscriptions: {
   // Options...
   },
   modules
   })
  ],
  modules
})

API

addSubscriptions([options])

Creates a new instance of the plugin with the given options. The following options HAS TO be provided to configure the plugin for your specific needs:

  • subscriptions <Object>: The keys are the mutations you want to listen for(including namespaces divided my forward-slash) and the value is the a callback function witch takes the state.
  • modules <ModuleTree<any>>: You could add the subscriptions inside your modules, and have it be namespaced.

Example

If you have multiple callback functions for one mutation you just add the different functions in an array.

import { Store } from 'vuex'
import addSubscriptions from 'vuex-subscriptions'
 
const store = new Store({
  // ...
  plugins: [
    addSubscriptions({
      subscriptions: {
       "user/loggedIn": (state, store) => {
       // fetch profile info
       },
       "user/loggedOut": [
       (state, store) => {
       // delete some data
       },
       (state, store) => {
       // navigate to another route
       }
       ]
      }
    })
  ]
})

License

MIT © Andreas Storesund Madsen

Readme

Keywords

none

Package Sidebar

Install

npm i vuex-subscriptions

Weekly Downloads

1

Version

1.1.0

License

MIT

Unpacked Size

44.5 kB

Total Files

40

Last publish

Collaborators

  • asmadsen