g-react-redux

1.0.0 • Public • Published

redux 和 react-redux

使用:

//初始化
import MyRedux, { connect, Provider } from 'MyRedux'
import React from 'react';
const reducers = {
    foo(state = { data: 'foo' }, { type, ...newState }) {
        if (type == 'foo') {
            return {...state, ...newState };
        }
        return state;
    },
    bar(state = { test: 'bar' }, { type, ...newState }) {
        if (type == 'bar') {
            return {...state, ...newState };
        }
        return state;
    }
}
const store = new MyRedux(reducers)

//connect react
const Home = (props) => {
            return (
                <p>{props.data.data}</p>
            )
        }
const Main = connect(({ home }) => ({ data:home }))(Home)
const App = ()=>(
    <Provider store={store}>
        <Main />
    </Provider>
)

//获取reducers的值
store.getState()

//dispatch 使用
//1.第二个参数为action
store.dispatch({ data: 111 }, 'foo')



//订阅与取消
let unsubscribe = store.subscribe(myFn) //订阅
unsubscribe()//取消

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.01latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.01

Package Sidebar

Install

npm i g-react-redux

Weekly Downloads

1

Version

1.0.0

License

ISC

Unpacked Size

18.8 kB

Total Files

7

Last publish

Collaborators

  • gujieyi1120