-
Notifications
You must be signed in to change notification settings - Fork 0
/
javascript.snippets
189 lines (150 loc) · 2.27 KB
/
javascript.snippets
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
180
181
182
183
184
185
186
187
188
#
# General ES6 snippets
#
# Generator function
snippet gfn
function* ${1:name}(${2}) {
yield ${3};
}
endsnippet
# Arrow function
snippet => "Arrow function" i
(${1}) => {
${2}
}
endsnippet
# Class
snippet class
class ${1:name} {
constructor(${2:arg}) {
${3:// init}
}
${4}
}
endsnippet
# For of loop
snippet forof
for (let ${1:s} of ${2:sequence}) {
${3}
}
endsnippet
# Import
snippet im
import ${1:foo} from '${2:bar}'
endsnippet
#
# React snippets
#
snippet cs "React.addons.classSet" b
var cx = React.addons.classSet
endsnippet
snippet cdm "component did mount" b
componentDidMount() {
${1}
}$0
endsnippet
snippet cdup "component did update" b
componentDidUpdate(prevProps, prevState) {
${1}
}$0
endsnippet
snippet cwm "component will mount" b
componentWillMount() {
${1}
}$0
endsnippet
snippet cwr "component will receive props" b
componentWillReceiveProps(nextProps) {
${1}
}$0
endsnippet
snippet cwun "component will unmount" b
componentWillUnmount() {
${1}
}$0
endsnippet
snippet cwu "component will update" b
componentWillUpdate(nextProps, nextState) {
${1}
}$0
endsnippet
snippet cx
cx({
${1}: ${2}
})
endsnippet
snippet fup
forceUpdate(${1:callback})
endsnippet
snippet gdp "get default props" b
getDefaultProps() {
return {
${1}
}
}$0
endsnippet
snippet gis "get initial state" b
getInitialState() {
return {
${1}: ${2}
}
}$0
endsnippet
snippet ism "is mounted"
isMounted()
endsnippet
snippet jsx "define jsx dom" b
/**
* @jsx React.DOM
*/
endsnippet
snippet ren
render() {
return (
${1:<div />}
)
}$0
endsnippet
snippet pt "propTypes" b
propTypes: {
${1}: React.PropTypes.${2:string}
}
endsnippet
snippet jsx "create class/component" b
import React, { ${1:PropTypes, }Component } from 'react'
class ${2:ClassName} extends Component {
$0
render() {
return (
${VISUAL}$4
)
}
}
${3:export default $2}
endsnippet
snippet ren
render: function() {
return (
${1:<div />}
)
}$0
endsnippet
snippet sst "set state" b
this.setState({
${1}: ${2}
})$0
endsnippet
snippet scu "should component update"
shouldComponentUpdate(nextProps, nextState) {
${1}
}$0
endsnippet
snippet props "get property" i
this.props.${1}
endsnippet
snippet state "get state" i
this.state.${1}
endsnippet
snippet trp
this.transferPropsTo(${VISUAL}$0)
endsnippet