💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
![](https://img.kancloud.cn/a7/c3/a7c39b953bb08188872a9afd47bb9d82_418x135.png) ![](https://img.kancloud.cn/42/04/420422cf664834f7a3bfa1b55bc9a8cd_702x234.png) ![](https://img.kancloud.cn/99/7d/997d629f12e805a82ebb54420b0708d4_737x300.png) ![](https://img.kancloud.cn/0b/40/0b4074a55b8ce462694f7c20b4676329_668x267.png) 在redux中派发的动作是纯对象({name:'xxx'}),不能是函数 ![](https://img.kancloud.cn/2f/c0/2fc016280e58c7f098bd125de22cfbef_747x364.png) koa模型 ![](https://img.kancloud.cn/b1/1b/b11b1de18a647654000885514c2502e3_871x480.png) ~~~ export default function compose(...funcs) { if (funcs.length === 0) { return arg => arg } if (funcs.length === 1) { return funcs[0] } return funcs.reduce((a, b) => (...args) => a(b(...args))) } ~~~ ![](https://img.kancloud.cn/d3/1c/d31c590a2c554fbb154c2f65f0be2613_1027x480.png) ~~~ import compose from './compose'; export default function applyMiddleware(...middlewares){ //middlewares=['thunk','logger'] return function(createStore){ return function(...args){ let store = createStore(...args); let dispatch; let middlewareAPI= { getState:store.getState,//获取仓库中的状态 dispatch:(...args)=>dispatch(...args)//派发动作 }; const chain = middlewares.map(middleware=>middleware(middlewareAPI)); dispatch = compose(...chain)(store.dispatch); return { ...store, dispatch }; } } } ~~~