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

mccree

v0.0.5

Published

Using redux with models

Downloads

8

Readme

McCree

McCree 基于 reduxredux-sagareact-redux 封装,提供了简单的方法来以 Model 的方式组织 statereducereffect。(Inspired by dva and mirror)

安装

npm install mccree --save

相关概念

Triads

我们把含有(非必需) statereducerseffects 的一个对象称为一个 Triad,如:

{
  state: {

  },
  reducers: {

  },
  effects: {

  }
}

当然,空对象 { } 同样可以作为一个 triad

(mccree 中,model 也为一个 triad,由 createStore 注册时传入)

state

表示 model 的状态数据。

reducers

redux 中 reducer,用来处理 action,改变 modelstate

effects

以 key / value 格式定义 effect,由 action 触发。

*(action, effects) {

}

参数中 effects 对象中包含 redux-saga 中所有可用的 effects,另提供了:

delay(ms):延迟。

execEffect(action):用于触发指定 effect,返回 Promise


action

使用 reducerseffects 中的 key 作为 action type,dispatch 后会触发相应 reducers/effects

API

combineTriads(...triads)

将多个 triad 合并为一个 triad


createStore(opts)

创建 redux store。

opts

  • middlewares

    middlewares: [
      routerMiddleware
    ]
  • models

    以 key / value 格式注册 model,其中 key 被设置为该 model 的命名空间(namespace),value 为一个 triad

    models: {
      userModel
    }
  • reducers

    指定 models 外的 reducer。

    reducers: {
      routing: routerReducer,
    }

<Provider store >

react-redux/Provider

connect([mapModelToProps], [mapStateToProps], [mapDispatchToProps], [mergeProps], [options])

connect 用于连接 redux 和组件。


awaitable(dispatcher)(payload): Promise

派发可触发 effect 的 action 时,返回 Promise,方便组件中部分操作需要 await 的情境。

await awaitable(this.props.userModel.xxx)({ /* payload */ })

actions 对象

包含全部的 Action Creator,以 namespace 划分,可用于 effects 等处,如:

yield put(actions.userModel.fetchData());