Status dispatching of my redux-thunk async action (post request)

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
2
down vote

favorite












I'm trying to dispatch to my reducers the current status of my request.
So far I'm wondering how refined the status publishing of my thunk action.



I feel like my code is very verbose and I wonder if I can reduce the line quantity of it.



I inform my store that the request have reached some step by dispatching a corresponding status.



Here my code :



// set the status available for my code with function arguments planned
export const postFileStatus = [
type: 'POST_FILE',status: request,
type: 'POST_FILE', status: success, response: res ,
type: 'POST_FILE', status: error, error: err

]

// dispatch the thunk to the redux middleware
const thunkFile = () => dispatch =>

// inform the request have started by retrieve the "request" status on my file
dispatch(postFileStatus.find(step => step.status === "request"));
Axios.post("http://localhost:7500/api/files",
"word": state.word,
"data": state.base64Data,
"id" : state.wordId
,
"Content-Type":"multipart/form-data"
)

// inform the request have succeed by retrieve the "success" status on my file
.then(res => dispatch(postFileStatus.find(step => step.status === "success"))
console.log(res) )
.catch(err =>

// inform the request have failed by retrieve the "error" status on my file
dispatch(postFileStatus.find(step => step.status === "error"))
console.log(" error :", error.response)
);









share|improve this question



























    up vote
    2
    down vote

    favorite












    I'm trying to dispatch to my reducers the current status of my request.
    So far I'm wondering how refined the status publishing of my thunk action.



    I feel like my code is very verbose and I wonder if I can reduce the line quantity of it.



    I inform my store that the request have reached some step by dispatching a corresponding status.



    Here my code :



    // set the status available for my code with function arguments planned
    export const postFileStatus = [
    type: 'POST_FILE',status: request,
    type: 'POST_FILE', status: success, response: res ,
    type: 'POST_FILE', status: error, error: err

    ]

    // dispatch the thunk to the redux middleware
    const thunkFile = () => dispatch =>

    // inform the request have started by retrieve the "request" status on my file
    dispatch(postFileStatus.find(step => step.status === "request"));
    Axios.post("http://localhost:7500/api/files",
    "word": state.word,
    "data": state.base64Data,
    "id" : state.wordId
    ,
    "Content-Type":"multipart/form-data"
    )

    // inform the request have succeed by retrieve the "success" status on my file
    .then(res => dispatch(postFileStatus.find(step => step.status === "success"))
    console.log(res) )
    .catch(err =>

    // inform the request have failed by retrieve the "error" status on my file
    dispatch(postFileStatus.find(step => step.status === "error"))
    console.log(" error :", error.response)
    );









    share|improve this question























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I'm trying to dispatch to my reducers the current status of my request.
      So far I'm wondering how refined the status publishing of my thunk action.



      I feel like my code is very verbose and I wonder if I can reduce the line quantity of it.



      I inform my store that the request have reached some step by dispatching a corresponding status.



      Here my code :



      // set the status available for my code with function arguments planned
      export const postFileStatus = [
      type: 'POST_FILE',status: request,
      type: 'POST_FILE', status: success, response: res ,
      type: 'POST_FILE', status: error, error: err

      ]

      // dispatch the thunk to the redux middleware
      const thunkFile = () => dispatch =>

      // inform the request have started by retrieve the "request" status on my file
      dispatch(postFileStatus.find(step => step.status === "request"));
      Axios.post("http://localhost:7500/api/files",
      "word": state.word,
      "data": state.base64Data,
      "id" : state.wordId
      ,
      "Content-Type":"multipart/form-data"
      )

      // inform the request have succeed by retrieve the "success" status on my file
      .then(res => dispatch(postFileStatus.find(step => step.status === "success"))
      console.log(res) )
      .catch(err =>

      // inform the request have failed by retrieve the "error" status on my file
      dispatch(postFileStatus.find(step => step.status === "error"))
      console.log(" error :", error.response)
      );









      share|improve this question













      I'm trying to dispatch to my reducers the current status of my request.
      So far I'm wondering how refined the status publishing of my thunk action.



      I feel like my code is very verbose and I wonder if I can reduce the line quantity of it.



      I inform my store that the request have reached some step by dispatching a corresponding status.



      Here my code :



      // set the status available for my code with function arguments planned
      export const postFileStatus = [
      type: 'POST_FILE',status: request,
      type: 'POST_FILE', status: success, response: res ,
      type: 'POST_FILE', status: error, error: err

      ]

      // dispatch the thunk to the redux middleware
      const thunkFile = () => dispatch =>

      // inform the request have started by retrieve the "request" status on my file
      dispatch(postFileStatus.find(step => step.status === "request"));
      Axios.post("http://localhost:7500/api/files",
      "word": state.word,
      "data": state.base64Data,
      "id" : state.wordId
      ,
      "Content-Type":"multipart/form-data"
      )

      // inform the request have succeed by retrieve the "success" status on my file
      .then(res => dispatch(postFileStatus.find(step => step.status === "success"))
      console.log(res) )
      .catch(err =>

      // inform the request have failed by retrieve the "error" status on my file
      dispatch(postFileStatus.find(step => step.status === "error"))
      console.log(" error :", error.response)
      );











      share|improve this question












      share|improve this question




      share|improve this question








      edited Jun 25 at 23:12
























      asked Jun 25 at 19:41









      Webman

      114




      114

























          active

          oldest

          votes











          Your Answer




          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "196"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f197228%2fstatus-dispatching-of-my-redux-thunk-async-action-post-request%23new-answer', 'question_page');

          );

          Post as a guest



































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes










           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f197228%2fstatus-dispatching-of-my-redux-thunk-async-action-post-request%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          Greedy Best First Search implementation in Rust

          Function to Return a JSON Like Objects Using VBA Collections and Arrays

          C++11 CLH Lock Implementation