veduxjs
--- title: Vedux.js - A lightweight Vuex alternative for Vue.js description: A ultra-lightweight state management library for Vue.js, it just does enough to help you manage state without locking you in. ---
Last updated 2 years ago by shailen .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install veduxjs 
SYNC missed versions from official npm registry.

title: Vedux.js - A lightweight Vuex alternative for Vue.js description: A ultra-lightweight state management library for Vue.js, it just does enough to help you manage state without locking you in.

Vedux

A ultra-lightweight state management library for Vue.js, it just does enough to help you manage state without locking you in.

Vedux is meant to be an alternative to Vuex as there is no such thing as actions, mutations or getters, you only have state that only gets mutated/accessed via the setState() and getState() functions. That's about it :)

You have full control over your state!

NOTE: This is just an experiment and my personal opinion, if you have any thoughts please feel free to submit and issue

Installation

$ yarn add veduxjs
import Vue from 'vue'
import { Vedux, Store } from 'veduxjs'

const store = new Store({
  counter: 0, 
  form: {
    email: null,
    name: null,
  },
})

Vue.use(Vedux, { store })

new Vue({}).$mount('#app')

Setup

After you have setup your store, you now have access to 4 methods:

  • getState() - Clones and returns the current instance of the state
  • setState() - Creates and returns a new instance of the state with your new values
  • module() - Allows you to create a module from a property on the state

getState()

const cloneOfTheState = store.getState()

// cloneOfTheState: { counter: 0, form: { email: null, name: null } }

const cloneOfTheState = store.getState('form')

// cloneOfTheState: { email: null, name: null }

const cloneOfTheState = store.getState('form.email')

// cloneOfTheState: null

const cloneOfTheState = store.getState(['form', 'email'])

// cloneOfTheState: null

setState()

const { counter: currentCounter } = store.getState() // currentCounter: 0

const { counter: newCounter } = store.setState(({ counter }) => ({ 
  counter: counter + 5
})) // newCounter: 5

module()

const counterModule = store.module('counter')

const { counter } = counterModule.setState(({ counter }) => counter + 5)

console.log(counter) // 5

Using it with Vue components

Just like Vuex, now you have access to the Vedux store with $store key, here is a simple example of how you can share state amongst 2 components

:::tip Vedux uses Vue.observable under the hood :::

store

const store = new Store({ text: null })

Vue.use(Vedux, { store })

new Vue({}).$mount('#app')

text component

<template>
  <p>
    {{ text }}
  </p>
</template>

<script>
export default {
  computed: {
    text() {
      return this.$store.getState('text')
    }
  }
}
</script>

input component

<template>
  <input :value="text" @input="updateText" type="text">
</template>

<script>
export default {
  computed: {
    text() {
      return this.$store.getState('text')
    }
  },
  methods: {
    updateText(newText) {
      const textModule = this.$store.module('text')

      textModule.setState(() => newText)
    }
  }
}
</script>

Current Tags

  • 0.0.27                                ...           beta (2 years ago)
  • 0.1.2                                ...           latest (2 years ago)

31 Versions

  • 0.1.2                                ...           2 years ago
  • 0.1.1                                ...           2 years ago
  • 0.1.0                                ...           2 years ago
  • 0.0.30                                ...           2 years ago
  • 0.0.29                                ...           2 years ago
  • 0.0.28                                ...           2 years ago
  • 0.0.27                                ...           2 years ago
  • 0.0.26                                ...           2 years ago
  • 0.0.25                                ...           2 years ago
  • 0.0.23                                ...           2 years ago
  • 0.0.22                                ...           2 years ago
  • 0.0.21                                ...           2 years ago
  • 0.0.20                                ...           2 years ago
  • 0.0.19                                ...           2 years ago
  • 0.0.18                                ...           2 years ago
  • 0.0.16                                ...           2 years ago
  • 0.0.15                                ...           2 years ago
  • 0.0.14                                ...           2 years ago
  • 0.0.13                                ...           2 years ago
  • 0.0.12                                ...           2 years ago
  • 0.0.11                                ...           2 years ago
  • 0.0.10                                ...           2 years ago
  • 0.0.9                                ...           2 years ago
  • 0.0.8                                ...           2 years ago
  • 0.0.7                                ...           2 years ago
  • 0.0.6                                ...           2 years ago
  • 0.0.5                                ...           2 years ago
  • 0.0.4                                ...           2 years ago
  • 0.0.3                                ...           2 years ago
  • 0.0.2                                ...           2 years ago
  • 0.0.1                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (4)
Dependents (1)

Copyright 2014 - 2021 © npmmirror.com |