反应本机Redux离线API响应



在redux-offline中如何查看还原器中的API响应。在我的代码下方,我可以在i可以看到我的请求数据中记录我的操作。在该还原器中如何记录我的响应数据。

我的代码在这里

action.js

 export const sample = (requestbodydata) => ({
          type: 'ACTION_CALL',
          payload: { requestbodydata },
          meta: {
            offline: {
              // the network action to execute:
              effect: { url: 'http://localhost:5000/api/v1/test/data', method: 'POST',  body: requestbodydata , headers: { 'content-type': 'application/x-www-form-urlencoded' } },
              // action to dispatch when effect succeeds:
              commit: { type: 'ACTION_CALL_COMMIT', meta: { requestbodydata } },
              // action to dispatch if network action fails permanently:
              rollback: { type: 'ACTION_CALL_ROLLBACK', meta: { requestbodydata } }
            }
          }
        });

reducer.js

export default function reducer(state = {}, action) {
    switch (action.type) {        
        case 'ACTION_CALL':
        console.log('get response'+JSON.stringify(action));
        case 'ACTION_CALL_COMMIT':
        console.log('ACTION_CALL_COMMIT')
        console.log('After commit response'+JSON.stringify(action));
        case 'ACTION_CALL_ROLLBACK':
        console.log('ACTION_CALL_ROLLBACK')

        default:
            return state
    }
}

store.js

    import { applyMiddleware, createStore, compose } from 'redux';
    import { offline } from '@redux-offline/redux-offline';
    import offlineConfig from '@redux-offline/redux-offline/lib/defaults';
    import reducer from './reducer';

const store = createStore(
  reducer,
  {},
  compose(
    applyMiddleware(thunk),
    offline(offlineConfig)
  )
);
export default store;

https://github.com/redux-offline/redux-offline/issues/63提到该提交会自动获取其action.payload设置为效果的响应。

也许可以用作以下内容:

case ACTION_CALL_COMMIT: 
  console.log(action.payload);

相关内容

  • 没有找到相关文章

最新更新