Skip to content

Commit 9568b3b

Browse files
author
minwe
committed
[*] change React pure function component template to function declaration, add rpfcaf for arrow function component
1 parent 218c26e commit 9568b3b

File tree

6 files changed

+71
-14
lines changed

6 files changed

+71
-14
lines changed

README.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ import React, {
6767
PropTypes,
6868
} from 'react';
6969

70-
const $COMPONENT$ = ($PARAMETER$) => {
70+
function $COMPONENT$($PARAMETER$) {
7171
return (
7272
<div>$END$</div>
7373
);
74-
};
74+
}
7575

7676
$COMPONENT$.propTypes = {};
7777
$COMPONENT$.defaultProps = {};
@@ -101,6 +101,26 @@ module.exports = $COMPONENT$;
101101

102102
```
103103

104+
### `rpfcaf`
105+
106+
```js
107+
import React, {
108+
PropTypes,
109+
} from 'react';
110+
111+
const $COMPONENT$ = ($PARAMETER$) => {
112+
return (
113+
<div>$END$</div>
114+
);
115+
};
116+
117+
$COMPONENT$.propTypes = {};
118+
$COMPONENT$.defaultProps = {};
119+
120+
export default $COMPONENT$;
121+
122+
```
123+
104124
### `rcc`
105125

106126
```js

build.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ let escapeTpl = (tpl) => {
2727
let data = [];
2828

2929
Object.keys(templates).forEach((k) => {
30-
var t = templates[k];
31-
var isMethod = (typeof t.tpl === 'string' && t.tpl.indexOf(': function') > -1);
32-
var tpl = t.tpl.next || t.tpl;
30+
const t = templates[k];
31+
const isMethod = (typeof t.tpl === 'string' && t.tpl.indexOf(': function') > -1);
32+
let tpl = t.tpl.next || t.tpl;
3333
tpl = tpl.replace(/: function/g, '');
3434

3535
isMethod && (tpl = tpl.replace(/},/g, '}'));
3636

37-
var snippet = {
37+
const snippet = {
3838
name: k,
3939
description: `React: ${t.description || t.tpl}`,
4040
tpl: escapeTpl(tpl),
@@ -47,8 +47,8 @@ Object.keys(templates).forEach((k) => {
4747
if (t.tpl.next ||
4848
(typeof t.tpl === 'string' && isMethod)) {
4949

50-
var tpl5 = t.tpl.es5 || t.tpl;
51-
var snippet5 = {
50+
const tpl5 = t.tpl.es5 || t.tpl;
51+
const snippet5 = {
5252
name: k + '5',
5353
description: `React: ${t.description || t.tpl}`,
5454
tpl: escapeTpl(tpl5),
@@ -62,8 +62,8 @@ Object.keys(templates).forEach((k) => {
6262

6363
function processEventsTpl(eventsMap) {
6464
Object.keys(eventsMap).forEach((key) => {
65-
var tplName = eventsMap[key];
66-
var tpl = `${key}={$END$}`;
65+
const tplName = eventsMap[key];
66+
const tpl = `${key}={$END$}`;
6767

6868
data.push({
6969
name: tplName,

jetbrains/templates/ReactJS.xml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
</template>
1616
<template
1717
name="rpfc"
18-
value="import React, {&#10; PropTypes,&#10;} from &apos;react&apos;;&#10;&#10;const $COMPONENT$ = ($PARAMETER$) =&gt; {&#10; return (&#10; &lt;div&gt;$END$&lt;/div&gt;&#10; );&#10;};&#10;&#10;$COMPONENT$.propTypes = {};&#10;$COMPONENT$.defaultProps = {};&#10;&#10;export default $COMPONENT$;&#10;"
18+
value="import React, {&#10; PropTypes,&#10;} from &apos;react&apos;;&#10;&#10;function $COMPONENT$($PARAMETER$) {&#10; return (&#10; &lt;div&gt;$END$&lt;/div&gt;&#10; );&#10;}&#10;&#10;$COMPONENT$.propTypes = {};&#10;$COMPONENT$.defaultProps = {};&#10;&#10;export default $COMPONENT$;&#10;"
1919
description="React: Create a pure function component"
2020
toReformat="true"
2121
toShortenFQNames="true">
@@ -43,6 +43,21 @@
4343
<option name="JS_STATEMENT" value="true" />
4444
</context>
4545
</template>
46+
<template
47+
name="rpfcaf"
48+
value="import React, {&#10; PropTypes,&#10;} from &apos;react&apos;;&#10;&#10;const $COMPONENT$ = ($PARAMETER$) =&gt; {&#10; return (&#10; &lt;div&gt;$END$&lt;/div&gt;&#10; );&#10;};&#10;&#10;$COMPONENT$.propTypes = {};&#10;$COMPONENT$.defaultProps = {};&#10;&#10;export default $COMPONENT$;&#10;"
49+
description="React: Create a pure function component using arrow function"
50+
toReformat="true"
51+
toShortenFQNames="true">
52+
<variable name="COMPONENT" expression="fileNameWithoutExtension()" defaultValue="" alwaysStopAt="true" />
53+
<variable name="PARAMETER" expression="" defaultValue="&quot;props&quot;" alwaysStopAt="true" />
54+
<context>
55+
<option name="JAVA_SCRIPT" value="true" />
56+
<option name="JS_EXPRESSION" value="true" />
57+
<option name="JSX_HTML" value="true" />
58+
<option name="JS_STATEMENT" value="true" />
59+
</context>
60+
</template>
4661
<template
4762
name="rcc"
4863
value="import React, {&#10; PropTypes,&#10;} from &apos;react&apos;;&#10;&#10;const $COMPONENT$ = React.createClass({&#10; render() {&#10; return (&#10; &lt;div&gt;$END$&lt;/div&gt;&#10; );&#10; }&#10;});&#10;&#10;export default $COMPONENT$;&#10;"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jetbrains-react",
3-
"version": "2.5.0",
3+
"version": "2.6.1",
44
"description": "React snippets(live templates) for JetBrains series editors.",
55
"main": "index.js",
66
"scripts": {

settings.jar

27 Bytes
Binary file not shown.

src/template.yaml

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ rpfc:
3737
PropTypes,
3838
} from 'react';
3939
40-
const $COMPONENT$ = ($PARAMETER$) => {
40+
function $COMPONENT$($PARAMETER$) {
4141
return (
4242
<div>$END$</div>
4343
);
44-
};
44+
}
4545
4646
$COMPONENT$.propTypes = {};
4747
$COMPONENT$.defaultProps = {};
@@ -69,6 +69,28 @@ rpfc:
6969
- {name: 'COMPONENT', expression: 'fileNameWithoutExtension()'}
7070
- {name: 'PARAMETER', defaultValue: '&quot;props&quot;'}
7171

72+
rpfcaf:
73+
description: Create a pure function component using arrow function
74+
tpl: |
75+
import React, {
76+
PropTypes,
77+
} from 'react';
78+
79+
const $COMPONENT$ = ($PARAMETER$) => {
80+
return (
81+
<div>$END$</div>
82+
);
83+
};
84+
85+
$COMPONENT$.propTypes = {};
86+
$COMPONENT$.defaultProps = {};
87+
88+
export default $COMPONENT$;
89+
90+
variables:
91+
- {name: 'COMPONENT', expression: 'fileNameWithoutExtension()'}
92+
- {name: 'PARAMETER', defaultValue: '&quot;props&quot;'}
93+
7294
rcc:
7395
description: Create a React.js component
7496
tpl:

0 commit comments

Comments
 (0)