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

vuex-plugin-jsdata

v0.3.0

Published

A vuex plugin to sync vuex store with jsdata-store

Downloads

18

Readme

vuex-jsdata-plugin

A simple attempt to help using jsdata alongside Vue.js: This plugin syncing Vuex store with js-data After each injection made by js-data some silent mutations are triggered to ensure vuex store is kept in sync with your ressources (and trigger reactivity).

Read more : https://github.com/js-data/js-data/issues/57

Dependencies

This plugin is developed for

[email protected]
[email protected]

You're welcome to contribute to help compatibility issues.

Usage

With NPM npm install vuex-plugin-jsdata

Then when you setup vuex:

import jsdataPlugin from 'vuex-plugin-jsdata'
import yourJsDataStore from 'xxxx'

const plugins = [
  jsdataPlugin(yourJsDataStore),
  ... // other plugins
]

new Vuex.Store({
  // state,
  // actions,
  // mutations,
  plugins,
})

How does it work ?

Every change in a js-data ressource are made with the DSInject method. The plugin manage the state tree(vuex) under a DS module by listening to the afterInject hook (js-data)

mutation

vuex-plugin-jsdata fire only one silent mutation : REFRESH_DATASTORE

getters

Although all local ressources injected in the jsdata-store can be found in the vuex store under the namespaced module DS, the plugin provide automatic getters for every model.

Ex:

// Register a model in js-data

export const User = store.defineResource({
  name: 'user',
  endpoint: 'users',
})
// in a .vue component
<script>
  import { mapGetters } from 'vuex'

  export default {
    name: 'User',
    props: {
      id: { required: true },
    },
    computed: {
      ...mapGetters(['DSUser']),
      user() {
        return this.DSUser[this.id]
      },
    },
  }
</script>

<template lang="jade">
  div.user
    pre {{ user | json }}
</template>

global helper

This plugin provide a handy way to make a ressource available inside components.

mapRessources

mapRessources([ { nameOfTheGetter: [nameOfTheRessource:string, id_key:string]}, ... ]) mapRessources is a getter factory designed to get a single record which id is computed from $vm[id_key]. Its really useful for getting specific records dynamicly (eg: get user with id picked from router params) example:

// in store - DSUsers: { 1: { name: 'Alex' } }
// component definition
// using the object spread operator
$vm = {
  data() {
    return {
      user_id: 1
    }
  },
  computed: {
    ...mapRessources([
      { user: ['User', 'user_id'] }
      { userFromRoute: ['User', '$route.params.id'] } // with vue-router
    ]),
  }
}
// Log
$vm.user.name -> 'Alex'
$vm.userFromRoute.name -> 'Alex'

Example

Clone the repo and run

npm install
npm run example-simple
=> go to /examples/simple

more to come ...

TO-DO

[ ] handle config options [ ] some examples

Contributions

are welcome :)