min-redux

1.0.1 • Public • Published

simple-redux

npm GitHub stars GitHub issues GitHub license

You will get how to write a redux-like by yourself

 
import { createStore } from './index'
 
function counter(state = 0, action) {
  switch(action.type) {
    case 'INCREMENT':
      return state + 1
    case 'DECREMENT':
      return state - 1
    default:
      return state
  }
}
 
const store = createStore(counter)
 
store.subscribe(() => console.log(store.getState()))
 
store.dispatch({ type: 'INCREMENT' })
// 1
store.dispatch({ type: 'INCREMENT' })
// 2
store.dispatch({ type: 'DECREMENT' })
// 1
 

参考文档

已支持

  • createStore
    • subscribe
    • getState
    • dispatch
  • combineReducers

待补充

  • bindActionCreators
  • applyMiddleware
  • actionCreator

Readme

Keywords

Package Sidebar

Install

npm i min-redux

Weekly Downloads

1

Version

1.0.1

License

MIT

Last publish

Collaborators

  • maczyt