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

redux-like-dva

v1.0.4-patch.1

Published

This is an imitation dva in the store management project, the purpose is to be able to use independently

Downloads

12

Readme

redux-like-dva

When I used the dva project, I had a great interest in its store management approach, and I have never used React to develop projects before, and have not come into contact with Redux and Saga, but have been developed by using dva My first react after the application, dva on the Store preparation method greatly stimulated me, and I would like to separate from the dva project, applied to the nodejs environment. But dva is a complete project, it seems that there is no intention to separate the opening of the Store management components, so I intend to imitate the management of the dva's management components to facilitate the use of independent

Latest version: 1.0.4

Links

CHANGELOG

Install

You can install this module with npm

npm install redux-like-dva

or use yarn

yarn add redux-like-dva

Usage

First, you need write model file, you can see dva document at here

  1. There is the model defintion, model.js
{
  namespace:'book',
  state: [],
  reducers:{
    add(state, action){
      const {payload} = action;
      return state.push(payload)
    },
    remove(state, {index}){
      return state.splice(index, 1)
    }
  },
  effects:{
    *find(action , {select, put}){
      ...
    }
  },
  subscriptions:{
    setup(){
      console.log('this will be start auto');
    }
  }
}

namespace is the name of the special state, it is uniquie

state the initialize state data, it can be array or object

reducers user defintion reducer function

effects user definition saga function

subscriptions user definition auto start function, they will be run after loaded all reducers and sagas

  1. Import Redux-like-dva and initialize store object
// My project requires redux and saga, and install together
// so you don't need import redux and saga again
const redux_dva = require('redux-like-dva');

// require the model defintion
redux_dva.add(require('./model.js'));

// you can add model any times
redux_dva.add(require('any_model.js'))

// Initlizile the reduxe store
const myStore = redux_dva.initStore();

// Now you can do anything, like orginial redux store
// getState() is the native function of redux
// you can use all the functions of redux
const currentState = myStore.getState();

// currentState contain full state tree
// you should use the special node of the state in your module
const books = currentState.book;
console.log(books);

// you can dispatch action like orginal redux
// the keypoint is the namespace
// you have to point out which namespace is your target
myStore.dispatch(
  {
    type:'book/add',
    payload: {
      title: 'My Book',
      author: 'aokihu'
    }
  }
)

const books = myStore.getState().book;
console.log(books);