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

@dx-groups/arthur

v1.1.1

Published

Downloads

10

Readme

arthur

NPM version build status Test coverage gemnasium deps npm download

基于业务形成的一个业务框架 ( Inspired by dva )

安装

@dx-groups/arthur

$ npm install @dx-groups/arthur --save
$ yarn add @dx-groups/arthur

用法

module.js

项目中使用 redux 管理状态库,当希望改变状态库的 state 时,使用 dispatch 发起一个 action ,根据 actionType 调用 reducers 改变 state 。arthur 中一个 module.js 包含了一个功能模块的 store、action、reducer 的实现。

import pageModule from './page/module'

// actionType
const GET_FIRST_LIST = 'spa/Arthur/GET_FIRST_LIST' 

export default {
  // 不能为空,组件会通过 namespace 访问state
  namespace: 'arthur',
  // 初始状态 state
  state: {
    first: ''
  },
  // redux actions,支持 redux-thunk 及 redux-promise 
  actions: {
    getFirstList(arg) {
      return dispatch => {
        dispatch({
          type: GET_FIRST_LIST,
          payload: {
            name: 'first'
          },
        })
      }
    }
  },
  // redux reducers, 同步操作用于更新 state
  reducers: {
    [GET_FIRST_LIST]: (state, action) => ({
      ...state,
      first: action.payload,
    })
  },
  children: [
    // 下级module.js
    pageModule
  ]
}

组件引入

import React, { Component } from 'react'
// 此 connect 方法是对 react-redux 中 connect 方法进行了二次封装
import { connect } from '@dx-groups/arthur'
class Page extends Component {
  render() {
    const { first } = this.props
    return (<div>{ first }</div>)
  }
}

const mapStateToProps = (state) => {
  return {
    // ...state.arthur.page 依然支持
    ...state['arthur.page']
  }
}

// 不需要 mapDispatchToProps 方法,store.dispatch 已经在 arthur 框架内塞入组件的 props 中
export default connect(['common.showListSpin', 'arthur.page'],mapStateToProps)(Page)

整合 module.js

import arthur from '@dx-groups/arthur'
import { createBrowserHistory } from '@dx-groups/arthur/history'
import Router from './router'
import arthurModule from '../modules/Arthur/module'

// 1. initialize
const app = arthur({
  history: createBrowserHistory()
})

// 2. execute initialization codes
app.init(() => dispatch => {
  
})

// 3. modules
app.modules([
  arthurModule,
])

// 4. router
app.router(Router)

// 5. start
app.start('#root')

export default app._store
  

DEMO

API

  • @dx-groups/arthur

    默认输出 arthur

    另外,还有两个方法

    • connect

      此 connect 方法是对 react-redux 中 connect 方法的二次封装

    • createAction

      是对 redux-actions 中 createAction 方法的映射,用于生成 Flux Standard Action

  • @dx-groups/arthur/history

    输出 history 的接口

  • @dx-groups/arthur/redux

    输出 redux 的接口

  • @dx-groups/arthur/router

    输出 react-router 的接口

  • @dx-groups/arthur/routerDom

    输出 react-router-dom 的接口

  • @dx-groups/arthur/routerRedux

    输出 react-router-redux 的接口