{"componentChunkName":"component---src-templates-lesson-js","path":"/phoenix-chat/snippets-and-aliases","result":{"data":{"mdx":{"body":"function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }\n\nfunction _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }\n\nfunction _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }\n\n/* @jsx mdx */\nvar _frontmatter = {\n  \"title\": \"Snippets and Aliases\",\n  \"order\": 8,\n  \"free\": true,\n  \"active\": true,\n  \"tech\": [\"atom\", \"vim\"]\n};\n\nvar makeShortcode = function makeShortcode(name) {\n  return function MDXDefaultShortcode(props) {\n    console.warn(\"Component \" + name + \" was not imported, exported, or provided by MDXProvider as global scope\");\n    return mdx(\"div\", props);\n  };\n};\n\nvar layoutProps = {\n  _frontmatter: _frontmatter\n};\nvar MDXLayout = \"wrapper\";\nreturn function MDXContent(_ref) {\n  var components = _ref.components,\n      props = _objectWithoutProperties(_ref, [\"components\"]);\n\n  return mdx(MDXLayout, _extends({}, layoutProps, props, {\n    components: components,\n    mdxType: \"MDXLayout\"\n  }), mdx(\"h1\", null, \"Snippets and Aliases\"), mdx(\"ul\", null, mdx(\"li\", {\n    \"parentName\": \"ul\"\n  }, \"Snippets\"), mdx(\"li\", {\n    \"parentName\": \"ul\"\n  }, \"Aliases\"), mdx(\"li\", {\n    \"parentName\": \"ul\"\n  }, \".vimrc\")), mdx(\"p\", null, \"Sometimes there is no way around writing repetitive code. Every React component needs to have some of the same boilerplate to make it function, and there are some bash commands that you have to type over and over again. This is where snippets and aliases come into play. This section is not strictly necessary for the rest of the series, but it might save you a lot of time down the road.\"), mdx(\"h2\", null, \"Snippets\"), mdx(\"p\", null, \"One handy feature you can do in most text editors is create a \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"snippet\"), \". If you are using Atom, you can change the \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"snippets.cson\"), \" file (\", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \".cson\"), \" is \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \".json\"), \" but for CoffeeScript) and add a text snippet.\"), mdx(\"pre\", null, mdx(\"code\", {\n    \"className\": \"language-bash\",\n    \"parentName\": \"pre\"\n  }, \"$ atom ~/.atom/snippets.cson\\n\")), mdx(\"p\", null, \"There should already be a file there with instructions on how to create a snippet. These will save you a lot of time and you can create your own if you find yourself typing out the same boilerplate code, over and over again. The code below will generate boilerplate for our typical React component.\"), mdx(\"pre\", null, mdx(\"code\", {\n    \"className\": \"language-coffee\",\n    \"parentName\": \"pre\"\n  }, \"# path: ~/.atom/snippets.cson\\n\\n'.source.js':\\n  'Standard component':\\n    'prefix': 'react'\\n    'body': '''\\n      import React from \\\"react\\\"\\n      import cssModules from \\\"react-css-modules\\\"\\n      import style from \\\"./style.css\\\"\\n\\n      class $1 extends React.Component {\\n        constructor(props) {\\n          super(props)\\n        }\\n\\n        render() {\\n          return (\\n            <div>\\n              $1 component\\n            </div>\\n          )\\n        }\\n      }\\n\\n      export default cssModules($1, style)\\n    '''\\n\")), mdx(\"p\", null, \"If you are not familiar with CoffeeScript, know that the whitespace matters. Each tab is the same as if you nested something within curly braces. Multiline strings also start and end with three apostrophes \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"'''\"), \".\"), mdx(\"p\", null, \"The first line tells Atom that you want to target files that end in \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \".js\"), \". Then we name our snippet, in this case \\\"Standard component\\\", but you can name it whatever you want. The \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"prefix\"), \" is what you type into your text editor before hitting the \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"tab\"), \" key. Again, you can name this whatever you want. Finally, the \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"body\"), \" is the code that is written when you press \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"tab\"), \" after typing the prefix.\"), mdx(\"p\", null, \"A handy thing to note is the \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"$1\"), \" keyword. In Atom, after you initiate a snippet, you can specify where you want the cursor to end up so you can start tying. If you want to get really fancy as we have done above, you can specify multiple cursors so you can type things like the name of the component in multiple places as the same time. If you have a second place you want to jump to, you can use \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"$2\"), \" and press \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"tab\"), \" to jump to it.\"), mdx(\"p\", null, \"The code above will generate your typical React component and will save you a ton of time over the course of this project. As you find yourself writing certain code over and over again, consider writing your own snippet.\"), mdx(\"p\", null, \"Another snippet that will come in handy is a basic test for a React component to make sure it renders properly. The syntax will make sense once we go over testing with \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"enzyme\"), \" in a future lesson.\"), mdx(\"pre\", null, mdx(\"code\", {\n    \"className\": \"language-coffee\",\n    \"parentName\": \"pre\"\n  }, \"'.source.js':\\n  'Standard component':\\n    ...\\n  'Standard test':\\n    'prefix': 'test'\\n    'body': '''\\n      import React from 'react'\\n      import expect from 'expect'\\n      import { shallow } from 'enzyme'\\n\\n      import { $1 } from './'\\n\\n      describe('<$1 />', () => {\\n        it('should render', () => {\\n          const renderedComponent = shallow(\\n            <$1 />\\n          )\\n          expect(renderedComponent.is('div')).toEqual(true)\\n        })\\n      })\\n    '''\\n\\n\")), mdx(\"h2\", null, \"Aliases\"), mdx(\"p\", null, \"Aliases let you run complex command line tasks with fewer characters. For example, instead of typing out \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"git add .\"), \", you could write an alias that lets you type out something as simple as \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"ga\"), \" which will accomplish the same thing.\"), mdx(\"p\", null, \"But this also comes in handy for much more complicated tasks. In this app, we will create a lot of components, and each component will have an \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"index.js\"), \", \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"spec.js\"), \", \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"style.css\"), \", and a \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"README.md\"), \" file. You could type them all out one by one every time, or you could write an alias to make this easier.\"), mdx(\"p\", null, \"If you're on a Mac, your aliases live in \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"~/.bash_profile\"), \". If you do not have this file, you should go ahead and create it.\"), mdx(\"pre\", null, mdx(\"code\", {\n    \"className\": \"language-bash\",\n    \"parentName\": \"pre\"\n  }, \"$ touch ~/.bash_profile\\n\")), mdx(\"p\", null, \"Here are a few simple git commands that save a couple minutes every day.\"), mdx(\"pre\", null, mdx(\"code\", {\n    \"className\": \"language-md\",\n    \"parentName\": \"pre\"\n  }, \"alias gs=\\\"git status\\\"\\nalias gd=\\\"git diff --stat\\\"\\nalias ga=\\\"git add --all\\\"\\n\")));\n}\n;\nMDXContent.isMDXComponent = true;","excerpt":"Snippets and Aliases Snippets Aliases .vimrc Sometimes there is no way around writing repetitive code. Every React component needs to have…","frontmatter":{"title":"Snippets and Aliases","order":8,"active":true,"free":true,"tech":["atom","vim"]}}},"pageContext":{"slug":"snippets-and-aliases","prevNode":{"frontmatter":{"title":"Style a React Component","active":true,"free":true,"order":7,"tech":["react"]},"fields":{"slug":"style-a-react-component"}},"nextNode":{"frontmatter":{"title":"Unit Tests with Enzyme","active":true,"free":true,"order":9,"tech":["react","enzyme","mocha"]},"fields":{"slug":"unit-tests-with-enzyme"}}}},"staticQueryHashes":["1723017916"]}