项目作者: xrr2016

项目描述 :
React Rematch Todos Example
高级语言: JavaScript
项目地址: git://github.com/xrr2016/rematch-todos.git
创建时间: 2016-11-10T01:59:28Z
项目社区:https://github.com/xrr2016/rematch-todos

开源协议:MIT License

下载


🔥 Rematch Todos Demo 🔥

GitHub issues Build

Why

这个项目起因是为了尝试一下rematch,它是一个基于 Redux 的状态管理框架,感觉跟 Vuex 有点相似,用以来比 Redux 简便很多,核心就是 model,dispatch 和 reducers,比 Redux 更好理解, 且无需配置就可使用 Redux Devtoolsreactotron

First step

定义你的 model, 然后用 init 方法初始化。

  1. // todos.js
  2. export const todos = {
  3. state: [],
  4. reducers: {
  5. addTodo () {...},
  6. removeTodo () {...},
  7. editTodo () {...}
  8. },
  9. effects: {
  10. async loadToads () {...}
  11. }
  12. }
  13. // index.js
  14. import { init } from '@rematch/core'
  15. import { todos } from 'path/todos'
  16. const store = init({
  17. models: {
  18. todos
  19. }
  20. })

Second step

将 store 用 Provider 赋予 App, 在 container 组件中调用 dispatch 方法, 让你定义的 reducers 响应 action 以更新 state。

  1. ;<Provider store={store}>
  2. <App ></App>
  3. </Provider>
  4. // todoInput
  5. import { dispatch } from '@rematch/core'
  6. dispatch.todos.addTodo(newTodo)
  7. // or
  8. dispatch({ type: 'todos/removeTodo', todoId })
  9. // You done!

Compare

compare

Live Demo

demo

Usage

  1. git clone git@github.com:xrr2016/rematch-todos.git
  2. cd rematch-todos && yarn
  3. yarn build
  4. serve -s build

Reference

Redux
Rematch
React-redux

License

MIT