Created
February 9, 2018 10:27
-
-
Save StaverDmitry/8e83caebc79bd0e49dd8d544bbb868b9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
// 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