Skip to content

Instantly share code, notes, and snippets.

@nelreina
Last active May 28, 2018 15:16
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 nelreina/f82f091ebbbf93e19ba0ff537b58ac77 to your computer and use it in GitHub Desktop.
Save nelreina/f82f091ebbbf93e19ba0ff537b58ac77 to your computer and use it in GitHub Desktop.
"Async Anonymous Call": {
"prefix": "asaw",
"body": [
"(async () => {",
" const ret = await ${1:methodName}",
" ${2}",
"})();"
],
"description": "Async Anonymous Call"
}
"Express Request Response Async": {
"prefix": "exarr",
"body": [
"async (req, res) => {",
" try {",
" const data = await ${1:method}();",
" res.${2:send}(${3:data})",
" } catch(error) {",
" logger.error(error);",
" res.status(503).send(error)",
" }",
"}"
],
"description": "Express Request Response Async"
}
"Express Request Response": {
"prefix": "exrr",
"body": [
"(req, res) => {",
" try {",
" const data = ${1:method}();",
" res.${2:send}(${3:data})",
" } catch(error) {",
" logger.error(error);",
" res.status(503).send(error)",
" }",
"}"
],
"description": "Express Request Response"
}
"React Class Component": {
"prefix": "nrrcc",
"body": [
"import React, { Component } from 'react'",
"",
"class $TM_FILENAME_BASE extends Component {",
" render () {",
" return (",
" <div>",
" {'$TM_FILENAME_BASE'}",
" </div>",
" )",
" }",
"}",
"",
"export default $TM_FILENAME_BASE"
],
"description": "React Class Component"
},
"React Stateless Component": {
"prefix": "nrrsc",
"body": [
"import React from 'react'",
"",
"const $TM_FILENAME_BASE = ({}) => {",
" return (",
" <div>",
" {'$TM_FILENAME_BASE'}",
" </div>",
" )",
"}",
"",
"export default $TM_FILENAME_BASE"
],
"description": "React Stateless Component"
}
"React Translate Class Component": {
"prefix": "rtcc",
"body": [
"import React, { Component } from 'react'",
"import { translate } from 'react-i18next';",
"",
"class $TM_FILENAME_BASE extends Component {",
" render () {",
" const { t } = this.props;",
" return (",
" <div>",
" {t('$TM_FILENAME_BASE')}",
" </div>",
" )",
" }",
"}",
"",
"export default translate()($TM_FILENAME_BASE)"
],
"description": "React Translate Class Component"
}
"React Translate Stateless Component": {
"prefix": "rtsc",
"body": [
"import React from 'react'",
"import { translate } from 'react-i18next';",
"",
"const $TM_FILENAME_BASE = ({ t }) => {",
" return (",
" <div>",
" {t('$TM_FILENAME_BASE')}",
" </div>",
" )",
"}",
"",
"export default translate()($TM_FILENAME_BASE)"
],
"description": "React Translate Stateless Component"
}
"Redux Async Call": {
"prefix": "rxapi",
"body": [
"import { assign } from 'lodash';",
"",
"const FETCHING = 'FETCHING_${1:${TM_FILENAME_BASE/(.*)/${1:/upcase}/}}';",
"const FETCH_SUCCESS = 'FETCH_${1:${TM_FILENAME_BASE/(.*)/${1:/upcase}/}}_SUCCESS';",
"const FETCH_ERROR = 'FETCH_${1:${TM_FILENAME_BASE/(.*)/${1:/upcase}/}}_ERROR';",
"",
"const initialState = {};",
"",
"export const fetch${2:${TM_FILENAME_BASE/(.*)/${1:/capitalize}/}} = () => async (dispatch, getState, api) => {",
" dispatch({ type: FETCHING });",
" try {",
" const payload = await api.get(`/${3:${TM_FILENAME_BASE/(.*)/${1:/downcase}/}}`);",
" dispatch({",
" type: FETCH_SUCCESS,",
" payload",
" });",
" } catch(error) {",
" dispatch({",
" type: FETCH_ERROR,",
" payload: error",
" });",
" }",
"};",
"",
"export default (state = initialState, action) => {",
" const { type, payload } = action;",
" switch (type) {",
" case FETCH_SUCCESS:",
" return assign({}, state, {",
" error: false,",
" fetching: false,",
" data: payload",
" });",
" case FETCHING:",
" return assign({}, state, { error: false, fetching: true, data: [] });",
" case FETCH_ERROR:",
" return assign({}, state, { error: true, message: payload, data: [] });",
"",
" default:",
" return state;",
" }",
"};",
""
],
"description": "Redux Async Call"
}
"Redux Async Action": {
"prefix": "rxasync",
"body": [
"const ${1:${ACTION/(*)${1:/upcase}}/} = '${1:ACTION/(*)${1:/upcase}/}';",
"export const login = () => async (dispatch, getState, api) => {",
" dispatch({ type: ${1:ACTION/(*)${1:/upcase}/} });",
" try {",
" const payload = await api.get(`/${3:${TM_FILENAME_BASE/(.*)/${1:/downcase}/}}`);",
" dispatch({",
" type: FETCH_SUCCESS,",
" payload",
" });",
" } catch(error) {",
" dispatch({",
" type: FETCH_ERROR,",
" payload: error",
" });",
" }",
"};"
],
"description": "Redux Async Action"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment