redux
redux 及周边
最简实现
// state dispatch reducer
export const createStore = (reducer, initState) => {
let state = initState
let listeners = []
function getState() {
return state
}
function dispatch(action) {
state = reducer(state, action)
listeners.forEach(i => i())
}
function subscribe(listener) {
listeners.push(listener)
return function unsubscribe() {
const index = listeners.indexOf(listener)
listeners.splice(index, 1)
}
}
// init
dispatch({ type: '@@redux/INIT' })
return { getState, dispatch, subscribe }
}redux toolkit
redux toolkit tips
createAsyncThunk
最后更新于