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

voir

v1.0.11

Published

A simple store for VueJS

Downloads

33

Readme

Voir

Voir is an incredibly simple store for keeping your mutations separate from your view components in Vue.js

##Features

  • Minimal code required to add new action behavior
  • ES5 friendly api
  • Redux Devtool support

##Install

npm:

npm install voir

CDN:

<script src="https://unpkg.com/voir@latest/voir.js"></script>

Usage

We're going to create a simple counter application.

Make a store

Let's start by creating the state for our app.

var state = { counter: 0 };

Next let's focus on the types of mutations we want to perform on this state. In Voir we separate out mutations into their own functions:

function counterMutations(state,action){
  	switch(action.type){
    	case "increment":
          state.counter += 1
          return;
  		case "decrement":
          state.counter -= 1
          return;
  		case "change":
          state.counter = action.data.number;
          return;        
    }
  }

Great! Now lets put our mutations and state together in a store that can expose our state and the ability to change it to others.

var store = Voir.createStore(state,[counterMutations]);

it's easy to add more mutation handlers if we want them

var store = Voir.createStore(state,[counterMutations,otherMutationHandler,...]);

Connect store to Vue

Now lets connect our Vue instance to the store so that any actions that come from our application go to our mutators.

<div id="demo">
      {{state.counter}}<button>+</button><button>-</button><button>Reset</button>
</div>
Vue.use(Voir,{store:store});
var demo = new Vue({
    el: '#demo',
    data:{
      state: store.state
    }
})

Dispatching actions

Dispatching actions in Voir is easy:

<div id="demo">
      {{state.counter}}
      <button v-on:click="dispatch('increment')">+</button>
      <button v-on:click="dispatch('decrement')">-</button>
      <button v-on:click="dispatch('change',{number:0})">Reset</button>
</div>
Vue.use(Voir,{store:store});
var demo = new Vue({
    el: '#demo',
    data:{
      state: store.state
    }
})

Dispatching Asynchronous Actions

Dispatching asynchronous in Voir is conventionally done by dispatching new actions. This encourages reuse and also isolated steps that can be observed easily in Redux DevTools (see below).

<div id="demo">
      {{state.counter}}
      <button v-on:click="dispatch('increment')">+</button>
      <button v-on:click="dispatch('decrement')">-</button>
      <button v-on:click="dispatch('change',{number:0})">Reset</button>
      <button v-on:click="dispatch('step')">Step</button>
</div>
function counterMutations(state,action,dispatch){
  	switch(action.type){
    	case "increment":
          state.counter += 1
          return;

      ...

      case "step":
          state.counter += 1
          setTimeout(function(){
            dispatch("increment:stepping first time");
            setTimeout(function(){
              dispatch("increment:stepping second time");
            },1000)
          },1000)
          return;     
    }
  }

Notice how comments can be added to an action on dispatch, allowing better logging in Redux DevTools.

Dispatching actions directly on the store

You may have scenerios that you desire to modify the store directly

store.dispatch("increment");

#Redux DevTools

Voir currently has support for logging through Redux DevTools. For more instructions on installing your dev tools, checkout https://github.com/gaearon/redux-devtools

Complete

<html>
<head>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.0.5/vue.min.js"></script>
  <script src="https://unpkg.com/voir@latest/voir.js"></script>
</head>
<body>
  <div id="demo">
      <p>{{state.counter}}</p>
      <button v-on:click="dispatch('increment')">+</button>
      <button v-on:click="dispatch('decrement')">-</button>
      <button v-on:click="dispatch('change',{number:0})">Reset</button>
      <button v-on:click="dispatch('step')">Step</button>
  </div>
</body>
<script>
  function counterMutations(state,action,dispatch){
    switch(action.type){
        case "increment":
            state.counter += 1
            return;
        case "decrement":
            state.counter -= 1
            return;
        case "change":
            state.counter = action.data.number;
            return;
        case "step":
            state.counter += 1
            setTimeout(function(){
              dispatch("increment:stepping first time");
              setTimeout(function(){
                dispatch("increment:stepping second time");
              },1000)
            },1000)
            return;
    }
  }

  var store = Voir.createStore({ counter: 0 }, [counterMutations]);

  Vue.use(Voir,{store:store});

  var demo = new Vue({
      el: '#demo',
      data:{
        state: store.state
      }
  })
</script>
</html>

See this demo at: https://richardanaya.github.io/voir/demo.html

voir