npm.io
1.0.1 • Published 9 years ago

min-redux

Licence
MIT
Version
1.0.1
Deps
0
Vulns
0
Weekly
0
Stars
1

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

Keywords