1.0.1 • Published 7 years ago

min-redux v1.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

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