-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjavascript.json
More file actions
179 lines (179 loc) · 5.26 KB
/
javascript.json
File metadata and controls
179 lines (179 loc) · 5.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
{
/*
// 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, ${id} and ${id:label} and ${1:label} for variables. Variables with the same id are connected.
// Example:
*/
"Print to console": {
"prefix": "logVariable",
"body": [
"console.log('${2:Console Message} ${1:Variable to Log}', ${1}); $3"
],
"description": "Log output to console"
},
"Print to console with pretty color": {
"prefix": "logColor",
"body": [
"console.log('%c${2:Console Message} ${1:Variable to Log}', 'color:${3:red}', ${1}); $4"
],
"description": "Log output to console"
},
"Print to Node Console with pretty color": {
"prefix": "nlog",
"body": [
"console.log('\\x1b[${1|30m,31m,32m,33m,34m,35m,36m,37m|}%s\\x1b[0m', `${2:Message} ${${variable}}`);"
],
"description": "Black:30m,Red:31m,Green:32m,Yellow:33m,Blue:34m,Magenta:35m,Cyan:36m,White:37m"
},
"Classic Component": {
"prefix": "ccomp",
"body": [
"import React, { Component } from 'react';",
"import PropTypes from 'prop-types';",
"",
"class ${1:Name of Component} extends Component {",
" state = {};",
"",
" // constructor(props) {}",
" // componentWillMount(){} // will be deprecated",
" // componentDidMount(){}",
" // componentWillReceiveProps(nextProps) {} // will be deprecated",
" // static getDerivedStateFromProps(nextProps, prevState) {}",
" // shouldComponentUpdate(nextProps, nextState) { return true; }",
" // componentWillUpdate(nextProps, nextState) {} // will be deprecated",
" // getSnapshotBeforeUpdate(prevProps, prevState) {}",
" // componentDidUpdate(prevProps, prevState, snapshot) {}",
" // componentWillUnmount() {}",
" // componentDidCatch(error, info) {}",
"",
" render() {",
" return (",
" <div className=\"${2:Component Class}\">",
" </div>",
" );",
" }",
"",
" static propTypes = {}",
"",
" static defaultProps = {}",
"}",
"",
"export default ${1:Name of Component};$3",
""
],
"description": "Classic react component created with the react create class method."
},
"Pure Component": {
"prefix": "pcomp",
"body": [
"import React, { PureComponent } from 'react';",
"import PropTypes from 'prop-types';",
"",
"class ${1:Name of PureComponent} extends PureComponent {",
" state = {};",
"",
" // constructor(props) {}",
" // componentWillMount(){} // will be deprecated",
" // componentDidMount(){}",
" // componentWillReceiveProps(nextProps) {} // will be deprecated",
" // static getDerivedStateFromProps(nextProps, prevState) {}",
" // shouldComponentUpdate(nextProps, nextState) { return true; }",
" // componentWillUpdate(nextProps, nextState) {} // will be deprecated",
" // getSnapshotBeforeUpdate(prevProps, prevState) {}",
" // componentDidUpdate(prevProps, prevState, snapshot) {}",
" // componentWillUnmount() {}",
" // componentDidCatch(error, info) {}",
"",
" render() {",
" return (",
" <div className=\"${2:Component Class}\">",
" </div>",
" );",
" }",
"",
" static propTypes = {}",
"",
" static defaultProps = {}",
"}",
"",
"export default ${1:Name of Component};$3",
""
],
"description": "React Pure Component for rendering optimizations"
},
"Functional Component": {
"prefix": "fcomp",
"body": [
"import React from 'react';",
"import PropTypes from 'prop-types';",
"",
"const ${1:Name} = props => (",
" <div className=\"${2:Component Class}\">",
" </div>",
");",
"",
"${1:Name}.propTypes = {};",
"",
"${1:Name}.defaultProps = {};",
"",
"export default ${1:Name};$3",
""
],
"description": "React Functional Component"
},
"Functional Component With Hooks": {
"prefix": "hcomp",
"body": [
"import React, { useState, useEffect } from 'react';",
"import PropTypes from 'prop-types';",
"",
"const ${1:Name} = props => {",
" return (",
" <div className=\"${2:Component Class}\">",
" </div>",
" );",
"}",
"",
"${1:Name}.propTypes = {};",
"",
"${1:Name}.defaultProps = {};",
"",
"export default ${1:Name};$3",
""
],
"description": "React Functional Component"
},
"Jest Unit Test": {
"prefix": "jtest",
"body": [
"import React from 'react'",
"import Adapter from 'enzyme-adapter-react-16'",
"import { configure, mount } from 'enzyme'",
"",
"configure({ adapter: new Adapter() })",
"",
"beforeAll(() => {})",
"beforeEach(() => {})",
"afterEach(() => {})",
"afterAll(() => {})",
"",
"const Example = props => (",
" <div className=\"example-component\">",
" <pre data-selector=\"stringify\">{JSON.stringify(props, null, 2)}</pre>",
" </div>",
")",
"",
"test('${1:Test Description}', () => {",
" const props = { test: 'Props' }",
" const stringified = JSON.stringify(props, null, 2)",
"",
" const wrapper = mount(<Example {...props} />)",
" const node = wrapper.find('[data-selector=\"stringify\"]')",
"",
" expect(node.text()).toBe(stringified)",
"})",
""
]
}
}