immutable结合redux的使用

实现一个案例如下:

immutable结合redux的使用_第1张图片

 

代码如下:

store.js

immutable结合redux的使用_第2张图片

 reducer1.js

immutable结合redux的使用_第3张图片

  reducer2.js

immutable结合redux的使用_第4张图片

 组件

import { Component } from "react";
import todoStore from './todoStore'
export default class RouterALL extends Component {
  state = todoStore.getState()
    render() {
        todoStore.subscribe(this.update.bind(this))
        console.log(this.state)
        let inputVal = this.state.inputReducer.getIn(['inputVal'])
        let list = this.state.liReducer.getIn(['list'])
        return (
            
{ list.map((item,index)=>{ return
  • {item}
  • })}
    ) } handleChange(e){ let action ={ type:'INPUT', value:e.target.value } todoStore.dispatch(action) } add(){ let action = { type:'ADD', value:this.state.inputReducer.getIn(['inputVal']) } todoStore.dispatch(action) } update(){ this.setState(todoStore.getState()) } deleteItem(index){ console.log(index,3333) let aa ={ type:'DELETE', value:index } todoStore.dispatch(aa) } }

    你可能感兴趣的:(react,前端,javascript)