ux核心思路和代碼解析
最近在公司內(nèi)部培訓(xùn)的時(shí)候,發(fā)現(xiàn)很多小伙伴只是會(huì)用redux、react-redux、redux-thunk的api,對(duì)于其中的實(shí)現(xiàn)原理和數(shù)據(jù)真正的流向不是特別的清楚,知其然,也要知其所以然,其實(shí)redux的源代碼非常簡(jiǎn)介,下面逐一介紹,
1.先看一個(gè)簡(jiǎn)單的redux應(yīng)用的例子:
import { createStore, combineReducers } from 'redux'; const year = (state, action) => { let defaultState = { year: 2017 } state = state || defaultState; switch (action.type) { case 'add': return { year: state.year + 1 }; break; case 'sub': return { year: state.year - 1 }; break; default: