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

dva-mini

v1.0.2

Published

a purely dva model package,independent other package

Downloads

1

Readme

dva-mini

a purely dva model package,independent other package.

dva-mini是一个支持按dva结构组织redux state,reducers,action,effect的极简库。

dvajs依赖太重,因依赖的库版本较老,目前按其文档创建应用都运行不起来。

轻量级的dva-mini支持dva模型,它没有依赖任何的库,不会因版本问题跑不起来。

dva-mini-deme

Usage start

  1. definition model
//file: model/count.js
export default {
    namespace: 'count',
    state: 0,
    reducers: {
      add (count) { 
          return count + 1 
      },
      minus (count) { 
          return count - 1 
      },
    },
    effects: {
        *add_effect(a,{put,select}) {
            var state = yield select();
            console.log("add_effect select state",state)
            //dispatch this namespace action
            //yield put({"type":"count/add"});
            yield put({"type":"add"});

            //dispatch other namespace action
            yield put({"type":"user/login"});
        }
    }
};
//file: model/user.js
export default {
    namespace: 'user',
    state: {
        name:"",
        status:"INIT",
    },
    reducers: {
      login(state) { 
          return {...state,status:"LOGIN"}
      },
      logout(state) { 
          return {...state,status:"LOGOUT"}
      },
    },
    effects: {
    }
}
  1. build dva

input models,convert output rootReducer,rootSaga

import CountModel from './model/count'
import UserModel from './model/user'

import {buildDva} from 'dva-mini'

import * as effects from 'redux-saga/effects';

let {rootReducer,rootSaga} = buildDva([
    CountModel,
    UserModel
],effects)
  1. use redux sage
import { createStore, applyMiddleware } from 'redux';
import createSagaMiddleware from 'redux-saga';

const sagaMiddleware = createSagaMiddleware();
const store = createStore(rootReducer, applyMiddleware(sagaMiddleware));

sagaMiddleware.run(rootSaga);
  1. whole page exp:
import { createStore, applyMiddleware } from 'redux';
import { Provider,connect } from 'react-redux';
import createSagaMiddleware from 'redux-saga';
import * as effects from 'redux-saga/effects';
import {buildDva} from 'dva-mini'

import CountModel from './model/count'
import UserModel from './model/user'

let {rootReducer,rootSaga} = buildDva([
    CountModel,
    UserModel
],effects)

const sagaMiddleware = createSagaMiddleware();
const store = createStore(rootReducer, applyMiddleware(sagaMiddleware));

sagaMiddleware.run(rootSaga);

const App = connect(({ count }) => ({
    count
  }))(function(props) {
    return (
      <div>
        <h2>{ props.count }</h2>
        <button key="add" onClick={() => { props.dispatch({type: 'count/add_effect'})}}>+</button>
        <button key="minus" onClick={() => { props.dispatch({type: 'count/minus'})}}>-</button>
      </div>
    );
  });

const MainPage= () => 
  <Provider store={store}>
    <App />
  </Provider>

export default MainPage