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

gi-mini-dvajs

v1.0.9

Published

Small DVA, multi page web solution.

Downloads

15

Readme

gi-mini-dvajs

  • gi 是基于 dva 的代码组织方式 + redux 数据管理思想开发的一个多页面解决方案。
  • 主要为了解决 dva 不够方便的多页面应用

特性

  • 易学易用,对 dva 代码风格一致,api 差不多
  • 轻量级,库非常小
  • elm 概念:通过 reducers, effects 和 subscriptions 组织 model

如何开始

安装

npm install --save gi-mini-dvajs

引入

// es6
import Gi from 'gi-mini-dvajs'

const app = Gi()

api

  • Gi()
    • use
    • model
    • router
    • start
  • connect

ps:

由于 api 和 dva 差不多,这边就不多介绍了,可以参考《dva 入门:手把手教你写应用 》

api 和 dva 不同的地方

app.use 方法里面的钩子只实现了部分

app.use({
	onAction: 
	,onError: 
	,onStateChange: 
})

app.router 的不同,dva 是使用 react-router 模块来实现单页路由,我们是多 html 使用同一的入口形式,所以路由注册方式不一样( 可以看我之前写的一篇博客,有说明同一入口的概念

import PageMoudle1 from 'PageMoudle1'
import PageMoudle2 from 'PageMoudle2'
import PageMoudle3 from 'PageMoudle4'

app.router(function ( register ) {

	register("/PageMoudle1.html", PageMoudle1)
	register("/PageMoudle2.html", PageMoudle2)
	register("/PageMoudle3.html", PageMoudle3)

})

connect,只实现了 mapStateToProps

example

app.js

import Gi from 'gi-mini-dvajs'

// app.use()

app.router(function ( register ) {

	register("/my-test.html", MyTest)
})

app.module({
  namespace: 'count',
  state: {
    record: 0,
    current: 0,
  },
  reducers: {
    addCount (state) {
      const newCurrent = state.current + 1;
      return { ...state,
        record: newCurrent > state.record ? newCurrent : state.record,
        current: newCurrent,
      };
    },
    minus(state) {
      return { ...state, current: state.current - 1}
    },
  },
  effects: {
    async add(action, { select, call, put }) {
      console.log( await select(({ count }) => {
        return count
      }))
      await put({ type: 'minus' })
    },
  },
  subscriptions: {
    keyboardWatcher() {
      console.log('--> subscripttion' )
    }
  }
})

app.start('#root')

my-test.js

import React, { Component } from 'react'
import util from './lib/util'
import { connect } from 'gi-mini-dvajs'

class MyTest extends Component {
  render () {
    const { count, dispatch } = this.props
    return <div >
       <h1>count.current ---> { count.current }</h1>
       <div style={{
         height: 200
         ,backgroundColor: 'red'
       }} onClick={() => {
         console.log( 'click')
         dispatch({type: 'count/add'})
      }}></div>
     </div>
  }
}


function mapStateToProps ( state ) {
  return state
}
export default connect( mapStateToProps )( MyTest )