Skip to content

Instantly share code, notes, and snippets.

@terrysahaidak
Created May 28, 2019 17:24
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 terrysahaidak/c9feb53233a31a9dadcd2306f0c48b84 to your computer and use it in GitHub Desktop.
Save terrysahaidak/c9feb53233a31a9dadcd2306f0c48b84 to your computer and use it in GitHub Desktop.
JavaScript snippets
{
// 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.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
"Redux ducks types group": {
"prefix": "rdtypes",
"body": [
"export const $1_START = '$2/$1_START';",
"export const $1_SUCCESS = '$2/$1_SUCCESS';",
"export const $1_ERROR = '$2/$1_ERROR';"
"",
],
"description": "Creates types group (start, success, error) with ducks' module prefix."
},
"Redux type": {
"prefix": "rtype",
"body": [
"export const $1 = '$1';",
"",
],
"description": "Creates redux type."
},
"Redux duck type": {
"prefix": "rdtype",
"body": [
"export const $1 = '$2/$1';",
"",
],
"description": "Creates redux ducks' module type."
},
"Redux ducks actions group": {
"prefix": "ractions",
"body": [
"export const $1Start = createAction(types.$2_START);",
"export const $1Success = createAction(types.$2_SUCCESS);",
"export const $1Error = createAction(types.$2_ERROR);"
"",
],
"description": "Creates redux actions group (start, success, error)."
},
"Redux action": {
"prefix": "raction",
"body": [
"export const $1 = createAction(types.$);",
],
"description": "Creates redux action."
},
"Redux thunk action (operation)": {
"prefix": "roperation",
"body": [
"function $1($2) {",
" return async function $1Thunk(dispatch$3) {",
" try {",
" dispatch(actions.$4.start($6));",
"",
" const res = await Api.$5($6);",
" dispatch(actions.$4.success($7));",
" } catch (err) {",
" dispatch(actions.$4.error({ message: err.message }));",
" }",
"};"
"",
],
"description": "Creates redux thunk action (operation)."
},
"MST createFlow": {
"prefix": "flow",
"body": [
"function $1($2) {",
" return function* $1Flow(flow, store) {",
" try {",
" flow.start();",
"",
" $3",
"",
" flow.success();",
" } catch (err) {",
" flow.failed(err);",
" }",
" }",
"}",
"",
],
"description": "Creates mst flow."
},
"MST asyncAction": {
"prefix": "tflow",
"body": [
"function $1($2) {",
" return async function $1Flow(flow, store) {",
" try {",
" flow.start();",
"",
" $3",
"",
" flow.success();",
" } catch (err) {",
" flow.failed(err);",
" }",
" }",
"}",
"",
],
"description": "Creates mst thunk flow."
},
"Creates react native styles": {
"prefix": "rnstylesheet",
"body": [
"import { StyleSheet } from 'react-native';",
"",
"const styles = StyleSheet.create({",
" $1: {",
" $2",
" },",
"});",
"",
"export default styles;",
"",
],
"description": "Creates react native styles."
},
"Creates react native dump component": {
"prefix": "rndump",
"body": [
"import React from 'react';",
"import T from 'prop-types';",
"import { $2 } from 'react-native';",
"import s from './styles';",
"",
"function $1() {",
" return ($3);",
"};",
"",
"$1.propTypes = {",
"",
"};",
"",
"export default $1;",
"",
],
},
"Creates react native smart component": {
"prefix": "rnsmart",
"body": [
"import React, { Component } from 'react';",
"import T from 'prop-types';",
"import { $2 } from 'react-native';",
"import s from './styles';",
"",
"class $1 extends Component {",
" render() {",
" return ($2);",
" }",
"}",
"",
"$1.propTypes = {",
"",
"};",
"",
"export default $1;",
"",
],
},
"Import statement": {
"prefix": "imp",
"body": [
"import $2 from '$1';",
],
},
"Destructive import statement": {
"prefix": "dimp",
"body": [
"import { $2 } from '$1';",
],
},
"React consturctor statement": {
"prefix": "rconstr",
"body": [
"constructor(props) {",
" super(props);",
"",
" $1",
"}",
""
],
},
"Class method bind": {
"prefix": "cbind",
"body": [
"this.$1 = this.$1.bind(this);",
],
},
"Creates react dump component": {
"prefix": "rdump",
"body": [
"import React from 'react';",
"import T from 'prop-types';",
"import s from './$1.module.scss';",
"",
"function $1() {",
" return ($3);",
"};",
"",
"$1.propTypes = {",
"",
"};",
"",
"export default $1;",
"",
],
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment