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

vue-own-redux

v0.2.0

Published

A connector to make a vue component has its own redux store.

Downloads

36

Readme

vue-own-redux

This is a connector to make a vue component has its own redux store.

demo: https://github.com/RequireSun/vue-single

How to use

  1. import the wrapper function and use it to wrap the object <script> tag exported.
import wrapper from 'vue-own-redux/wrapper';

export default wrapper({
    name: 'xxx',
    ...
});
  1. create a store and its actions with redux and redux-actions.

    use bindActions to bind actions on the store.

    counter.js

import {createStore} from 'redux';
import {createActions,handleActions} from 'redux-actions';
import bindActions from 'vue-own-redux/bindActions';

const ADD = 'ADD';
const MINUS = 'MINUS';

export default function () {
   const reducers = handleActions({
       [ADD](state, action) {
           return {
               ...state,
               count: state.count + action.payload.amount,
           }
       },
       [MINUS](state, action) {
           return {
               ...state,
               count: state.count - action.payload.amount,
           }
       }
   }, {
       count: 0,
   });

   const store = createStore(reducers);

   const actions = bindActions(store, createActions({
       [ADD]: info => info,
       [MINUS]: info => info,
   }));

   return {
       actions,
       store,
   };
}
  1. import your component where you want, create new store & actions, then pass them into your component.

    the business property must have two properties store and actions.

    businesses property also can be an object that contains many businesses, when you pass a businesses object in this format, the state property in Vue component will also provide states in this format.

    page.vue

<template>
    <div>
        <h1>{{ msg }}</h1>
        <counter :business="stores"></counter>
        <counter :business="stores2"></counter>
    </div>
</template>

<script>
import counter from '../counter';
import elCounter from '../counter.vue';

export default {
    name: 'HelloWorld',
    components: {
        counter: elCounter,
    },
    data () {
        return {
            msg: 'Welcome to Your Vue.js App',
            stores: {},
            stores2: {},
        }
    },
    mounted () {
        this.stores = counter();
        this.stores2 = counter();
    }
}
</script>

Outdated

  1. import the component of vue-own-redux as a component of your vue component.

    define the way how parent element pass the store and actions in:

    1. provide stores in the props property.
    2. pass the stores into connect component.
    3. use the state and action in the children components of connect by the slot-scope feature.
<template>
  <div>
    <connect :stores="stores">
      <div slot-scope="scope">
        <h1>{{scope.state}}</h1>
        <button @click="add">actions in methods</button>
        <button @click={scope.action.minus({amount:1})}>actions on element</button>
      </div>
    </connect>
  </div>
</template>

<script>
import connect from 'vue-own-redux';

export default {
    name: 'my-component',
    props: ['stores'],
    components: {connect},
};
</script>
  1. create a store and its actions with redux and redux-actions.

    use bindActions to bind actions on the store.

    counter.js

import {createStore} from 'redux';
import {createActions,handleActions} from 'redux-actions';
import bindActions from 'vue-own-redux/bindActions';

const ADD = 'ADD';
const MINUS = 'MINUS';

export default function () {
   const reducers = handleActions({
       [ADD](state, action) {
           return {
               ...state,
               count: state.count + action.payload.amount,
           }
       },
       [MINUS](state, action) {
           return {
               ...state,
               count: state.count - action.payload.amount,
           }
       }
   }, {
       count: 0,
   });

   const store = createStore(reducers);

   const actions = bindActions(store, createActions({
       [ADD]: info => info,
       [MINUS]: info => info,
   }));

   return {
       actions,
       store,
   };
}
  1. import your component where you want, create new store & actions, then pass them into your component.

    the stores property must have two properties store and actions.

    page.vue

<template>
    <div>
        <h1>{{ msg }}</h1>
        <counter :stores="stores"></counter>
        <counter :stores="stores2"></counter>
    </div>
</template>

<script>
import counter from '../counter';
import elCounter from '../counter.vue';

export default {
    name: 'HelloWorld',
    components: {
        counter: elCounter,
    },
    data () {
        return {
            msg: 'Welcome to Your Vue.js App',
            stores: {},
            stores2: {},
        }
    },
    mounted () {
        this.stores = counter();
        this.stores2 = counter();
    }
}
</script>