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 🙏

© 2026 – Pkg Stats / Ryan Hefner

vuex-rails-plugin

v1.0.2

Published

A Vuex plugin that easily maps Rails resources to Vuex modules

Readme

VuexRailsPlugin

A Vuex plugin that easily maps Rails resources to Vuex modules

The idea of this plugin is to easily incorporate conventional rest endpoints defined when scaffolding Rails resources and map the responses to appropriate state in Vuex. ex. resources :posts generates the following endpoints:

  • GET|POST /posts
  • GET|PUT /posts/:id
  • DELETE /posts/:id

Install

$ npm i vuex-rails-plugin

Usage

The plugin can be imported into any Vuex store like so:

// store.js
import Vuex from 'vuex'
import Vue from 'vue'
Vue.use(Vuex)
import VuexRailsPlugin from 'vuex-rails-plugin/src/VuexRailsPlugin'

export default new Vuex.Store({
  // ...
  plugins: [
    VuexRailsPlugin('posts'),
    VuexRailsPlugin('categories')
  ]
})

This example defines Vuex modules for 'posts' and 'categories' namespaces. It supports the following state:

  • all - items returned from the index action
  • current - set when the show action is called
  • error - set if any errors occur such as validations

The state can be mapped to any Vue component using mapState

// some-component.vue
import { mapState } from 'vuex'
export default {
  computed: {
    ...mapState('posts', {
      posts: state => state.all,
      currentPost: state => state.current
      error: state => state.error
    })
  }
}

Actions can also be called by using mapActions

// some-component.vue
import { mapActions } from 'vuex'
export default {
  // ...
  methods: {
    ...mapActions('posts', {
      getPosts: 'getAll', // ex. this.getAll()
      getPost: 'get', // ex. this.getPost(id)
      createPost: 'create', // ex. this.createPost({title: 'Bad', body: 'Ass'})
      updatePost: 'update', // ex. this.updatePost({id: 1, title: 'Bad', body: 'Mama Jama'})
      destroyPost: 'destroy' // ex. this.destroyPost({})
    })
  }
}

Params are supported

this.getPosts({page: 1, limit: 10})

Use directly in a form

export default {
  data() {
    return {
      newPost: {
        title: '',
        body: ''
      }
    }
  }
}
<form @submit.prevent="createPost(newPost)">
  <label>Title</label>
  <input type="text" v-model="newPost.title"/>
  <label>Body</label>
  <input type="text" v-model="newPost.body">
  <buton type="submit">Submit</buton>
</form>

Promises supported

export default {
  // ...
  methods: {
    promiseMeThisPostWillCreate() {
      this.createPost(this.newPost)
        .then(createdPost => {
          alert('Thanks for keeping your promise!')
        })
        .catch(err => {
          alert('Why did you break my promise?')
        })
    }
  }
}

TODO

  • Support nested resources ex. /categories/:category_id/posts
  • Support other options that may be necessary to support custom getters, filters, etc.