//action
function add(task) {
    return {type: ADD_TASK, task};
}

//reducer
function func1(state = [], action) {
    if (action.type == ADD_TASK) {
        return [...state, action.task];
    }
}

function reducer(...args) {
    return func1(...args) || func2(...args) || args[0];
}

//App
class App extends Component {
render() {
        const {taskList} = this.props;
    }
}

// Which props do we want to inject, given the global state
function selector(state = []) {
    return {
        taskList: state
    }
}

export const store = createStore(reducer);
// 包装 component ,注入 dispatch 和 state 到其默认的 connect(select)(App) 中;
export default connect(selector)(App);

初始化顺序:

  1. createStore
  2. reducer(state,action)
  3. connect(selector)App
  4. selector(state)
  5. App.render(props:{dispatch,…selector#Return})

事件触发顺序:

  1. dispatch(action)
  2. action
  3. reducer(state,action)
  4. selector(state)
  5. App.render(props:{dispatch,…selector#Return})

发表评论

邮箱地址不会被公开。 必填项已用*标注