Skip to content

Instantly share code, notes, and snippets.

@StaverDmitry
Created February 9, 2018 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StaverDmitry/8e83caebc79bd0e49dd8d544bbb868b9 to your computer and use it in GitHub Desktop.
Save StaverDmitry/8e83caebc79bd0e49dd8d544bbb868b9 to your computer and use it in GitHub Desktop.
{
// Place your snippets for javascript here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
"Redux Axios action": {
"description": "Create axios action",
"prefix": "axios_action",
"body": [
"const $2_SUCCESS = '$2_SUCCESS'",
"const $2_ERROR = '$2_ERROR'",
"",
"export const $1 = () => (dispatch) => {",
" axios.post(",
" `${config.apiUrl}/$0`, data,",
" { headers: { Authorization: `Bearer ${localStorage.getItem('token')}` } },",
" )",
" .then((response) => {",
" $3 = response.data.$3",
" dispatch($1Success($3));",
" })",
" .catch((error) => {",
" dispatch($1Error(error));",
" });",
"}",
"",
"function $1Success(file) {",
" return {",
" type: constants.$2_SUCCESS,",
" file,",
" };",
"};",
"",
"function $1Error(error) {",
" return {",
" type: constants.$2_ERROR,",
" error,",
" };",
"};",
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment