Status dispatching of my redux-thunk async action (post request)
Clash 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)
);
javascript asynchronous redux
add a comment |Â
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)
);
javascript asynchronous redux
add a comment |Â
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)
);
javascript asynchronous redux
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)
);
javascript asynchronous redux
edited Jun 25 at 23:12
asked Jun 25 at 19:41
Webman
114
114
add a comment |Â
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password