Skip to content

Commit fe69ea5

Browse files
committed
feat: enable data-component-custom, do not generate redux connections
1 parent 0440738 commit fe69ea5

File tree

6 files changed

+66
-7
lines changed

6 files changed

+66
-7
lines changed

data-attributes.README.md

+13-7
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,26 @@
9595

9696
FROM:
9797
```
98-
<div
99-
data-component-name="Login"
100-
data-component-custom="true">
101-
</div>
98+
// data-component-custom.html
99+
<html>
100+
<body>
101+
<div data-component-name="Login" data-component-custom="true">
102+
<form>
103+
<input type="text" id="user" />
104+
</form>
105+
</div>
106+
</body>
107+
</html>
102108
```
103109

104110
TO:
105111
```
106-
// Login.jsx
112+
// DataComponentCustom.jsx
107113
import React from 'react';
108114
109-
export default class Login extends React.Component {
115+
export default class DataComponentCustom extends React.Component {
110116
render () {
111-
return null;
117+
return <div><Login/></div>;
112118
}
113119
}
114120
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from 'react';
2+
import Login from './Login';
3+
import custom from '../../custom/index';
4+
5+
class DataComponentCustom extends React.Component {
6+
render() {
7+
return (
8+
<div>
9+
<Login></Login>
10+
</div>
11+
);
12+
}
13+
}
14+
;
15+
16+
const customize = custom['components/DataComponentCustom'] || ((x) => x);
17+
const DataComponentCustomWithCustom = customize(DataComponentCustom, {
18+
React,
19+
Login
20+
});
21+
22+
export default DataComponentCustomWithCustom;
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<html>
2+
<body>
3+
<div data-component-name="Login" data-component-custom="true">
4+
<form>
5+
<input type="text" id="user" />
6+
</form>
7+
</div>
8+
</body>
9+
</html>

lib/plugins/redux/process-each-jsx-snippet/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const traverse = require('babel-traverse').default;
22
const processHtmlAction = require('./process-html-action');
33
const processErrorExplanation = require('./process-error-explanation');
44
const processValue = require('./process-value');
5+
const getAttr = require('../../../helpers/get-attr');
56

67
function addStateAndAction(
78
{ nodeState, nodeAction }, state, action
@@ -23,6 +24,10 @@ module.exports = function processEachJsxSnippet({ component, components, options
2324

2425
traverse(ast, {
2526
JSXElement({ node }) {
27+
const isCustom = getAttr({ node, name: 'data-component-custom' });
28+
if (isCustom) {
29+
return true;
30+
}
2631
addStateAndAction(processHtmlAction({ component, node }), state, action);
2732
addStateAndAction(processErrorExplanation({ component, node }), state, action);
2833
addStateAndAction(processValue({ component, node }), state, action);

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"semantic-release": "^4.3.5"
4343
},
4444
"dependencies": {
45+
"babel-traverse": "git://github.com/poetic/babel-traverse.git#3272f03380b22ebf1608b0a9b89bff991c746695",
4546
"babel-generator": "^6.11.0",
4647
"babylon": "^6.8.2",
4748
"chalk": "^1.1.3",
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* eslint-env mocha */
2+
const assert = require('chai').assert;
3+
const reacterminator = require('../../lib/index');
4+
const { checkFiles } = require('../helpers');
5+
6+
describe('data-component-custom', function () {
7+
it('should create an empty custom component', function () {
8+
checkFiles({
9+
inputPath: './examples/test/data-component-custom.html',
10+
outputDir: 'data-component-custom',
11+
outputFiles: [
12+
'generated/components/DataComponentCustom.jsx',
13+
]
14+
});
15+
});
16+
});

0 commit comments

Comments
 (0)