Skip to content
Vuex like state management library.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE
README.md
index.js update author Apr 3, 2019
package.json

README.md

Vanix

Vuex like state management library.
Not support component.
Support ES6 or later. Please transpile if want supporting ES5.

install

$ npm install vanix --save-dev

How to use

store.js

import Vanix from 'vanix'

const state = {
  alpha: 'Alpha',
  beta: 'Beta',
  charlie: 'Charlie'
}

const mutations = {
  setCharlie(state, data) {
    state.charlie = data
  }
}

const actions = {
  async asyncSetCharlie(context, data) {
    // const { commit, state, getters, dispatch } = context
    await new Promise((resolve) => {
      setTimeout(() => {
        context.commit('setCharlie', data)
        resolve()
      }, 1000)
    })
  }
}

const vanix = new Vanix({ state, mutations, actions })

export const store = vanix.create()

main.js

import { store } from './store'

// get
console.log(store.state.alpha) // Alpha

// set (commit)
store.commit('setCharlie', 'New Charlie')

// async commit
store.dispatch('asyncSetCharlie', 'Super Charlie')

// observe
const storeObserveObj = store.observe({
  beta(state) {
    console.log(state.beta) // Beta
  }
})

// unobserve
store.unobserve(storeObserveObj)

Destroy

import Vanix from 'vanix'

const vanix = new Vanix()
const store = vanix.create()

vanix.destroy()

License

MIT

You can’t perform that action at this time.