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 🙏

© 2026 – Pkg Stats / Ryan Hefner

dva-model

v2.4.1

Published

dva.js Model

Readme

dva-model

0.0.13 升级到2.X

去除了很多不必要的方法 修复了已知的BUG effect不再支持{api, success...}的写法了,请使用下面的写法

effect(api, success, fail = 'failed', cache = null)

effect不再支持callback, 也没有返回值了 effect不再支持afterXXX了

去除了所有关于loading的东西, dva本身已经有插件支持了

reducer 在处理 action的时候, 0.0.13 是 action.result 表示是从 effect中处理的内容, 现在统一成action.payload 原action.payload 已经去除, 只能从 action.source里获取

Install 安装

npm install dva-model

Use 使用

import Model from 'dva-model';
import effect from 'dva-model/effect';
import {list, item, create, modify, remove, publish, unPublish} from './service/banner'; //远程API接口


export default Model({
  namespace:'banner',
  subscriptions: {
    setup({dispatch, history}) {
      history.listen(location =>dispatch({
        type: 'list',
        payload: location.query
      }));
    },
  },
  effects: {
    publish: effect(publish, 'modifySuccess'),
    unPublish: effect(unPublish, 'modifySuccess'),
  },
  reducers:{
    //以下自动生成
    //set(state, action:{payload}), // 将payload直接设置到state[namespace]中
    //clean(state, action:{payload}), //清除此名字空间下的所有state, 并重新设置成payload中传递的数据

    //以下视service中是否传入相应API而生成
    //listSuccess(state, action),   // 将result中的list, total设置到state[namespace]中
    //itemSuccess(state, action),   // 将result整体做为item 设置到state[namespace]中
    //createSuccess(state, action), // 同itemSuccess, 并total+1, list中添加item
    //modifySuccess(state, action), // 同itemSuccess, 并替换list中的item 根据id
    //removeSuccess(state, action), // total-1, list中删除此id的元素
  }
}, {
  list, item, create, modify, remove, //service api 会自动生成 effect与reducer
},{
  //cache 缓存机制, 可以将远程调用的结果缓存起来
  list: listCache, //对应到 effects.list 调用
  item: itemCache, //对应到 effects.item 调用
});

Model(model, service, cache) 会自动处理 effects 与 reducers, 并且effect 调用时会put({loading, apiName+'Loading'})到state[namespace]; effect结束时,loading, apiName+'Loading'会从state[namespce]中删除;

一般的 service 中定义远程调用接口

export async function list(data) {
  return request('/api/banner', {data, method: 'GET'});
}

后台返回的数据结构(JSON)

{
  status: number, //1:成功, 其他错误,
  code: number,   //错误码,
  message: string, //错误消息
  result:{          //成功时的返回数据  //itemSuccess 会将此整体做为item设置到state

    // listSuccess 会将此数据设置到state中
    list: [],      // RESTFul index
    total: number, // RESTFul index, 记录总数,可用于分页

    id,             // RESTFul show upadte(PUT) patch(PATCH) delete(DELETE)
  }
}

Cache 缓存

function Cache(data){
  if(!!data){
    //存
  }else{
    return {} //取
  }
}
Cahce.clean = function(){} //清除