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

@leopiccionia/vue-redux

v0.1.3

Published

A Redux wrapper for Vue

Downloads

6

Readme

vue-redux

vue-redux is a Redux wrapper for Vue that exposes an API similar to Vuex.

It's a tiny package (~1.5 KB), including some optional helpers.

When should you use it

It's intended for users already using Redux, or by those that need a way to access the store outside of Vue (e.g. using micro-frontends).

Vuex is an excellent solution, deeply integrated with Vue ecosystem and tooling, that should be carefully considered.

Installation

NPM

npm install --save @leopiccionia/vue-redux

Yarn

yarn add @leopiccionia/vue-redux

Usage

Plugin

The package exposes a Vue plugin called VueRedux. You'll need to pass the store to the app instance.

import Vue from 'vue'
import { VueRedux } from '@leopiccionia/vue-redux'

import App from './App.vue'
import store from './store.js'

Vue.use(VueRedux)

new Vue({
  store,
  render: h => h(App)
}).$mount('#app')

Then you'll be able to use the following read-only properties inside your components:

  • this.$store: The provided store, so you can use this.$store.dispatch, this.$store.subscribe, etc.
  • this.$state: The current state. It's tracked by Vue reactivity system, so you can use it inside templates and computed properties.

Just like in vanilla Redux, you should mutate state only via dispatching actions.

For debugging the current state, use Redux DevTools.

Compat mode

For enhanced compatibility with Vuex API, use the experimental "compat" build. All named exports have the same alias.

For ES modules:

- import { ... } from '@leopiccionia/vue-redux'
+ import { ... } from '@leopiccionia/vue-redux/dist/compat'

For CommonJS:

- const { ... } = require('@leopiccionia/vue-redux')
+ const { ... } = require('@leopiccionia/vue-redux/dist/compat.umd')

In this mode, the Vue-tracked store Redux is available at this.$store.state instead of this.$state, just like Vuex.

Helpers

mapActions

This function receives an object whose values are the action creators that should be dispatched.

Differently from Vuex, Redux actions aren't coupled with the store, so they need to be imported inside the component.

import { mapActions } from '@leopiccionia/vue-redux'
import { setName } from '../store/actions'

export default {
  methods: {
    ...mapActions({ setName })
  }
}

Is equivalent to:

import { setName } from '../store/actions'

export default {
  methods: {
    setName (...args) {
      this.$store.dispatch(setName(...args))
    }
  }
}

mapState

This function can receive an object, whose values can be functions, that maps the state, or strings, that represent paths in the state tree.

import { mapState } from '@leopiccionia/vue-redux'

export default {
  computed: {
    ...mapState({
      fullName: state => state.firstName + ' ' + state.lastName,
      address: 'address'
    })
  }
}

Is equivalent to:

export default {
  computed: {
    fullName () {
      return this.$state.firstName + ' ' + this.$state.lastName
    },
    address () {
      return this.$state.address
    }
  }
}

Alternatively, the function can receive an array of strings.

import { mapState } from '@leopiccionia/vue-redux'

export default {
  computed: {
    ...mapState(['name', 'sale.cart'])
  }
}

Is equivalent to:

export default {
  computed: {
    name () {
      return this.$state.name
    },
    cart () {
      return this.$state.sale.cart
    }
  }
}

Examples

Roadmap

  • [ ] Add TypeScript types
  • [x] Add unit tests