Skip to content

Commit 8330402

Browse files
committed
refactor: get rid of Object.assign req
1 parent df6befd commit 8330402

17 files changed

+377
-153
lines changed

examples/webpack.config.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
var path = require('path');
2+
3+
module.exports = function(directory) {
4+
return {
5+
entry: './index.js',
6+
output: {
7+
path: 'bundle',
8+
filename: 'bundle.js',
9+
},
10+
devtool: 'cheap-eval-source-map',
11+
resolve: {
12+
fallback: path.join(directory, 'node_modules'),
13+
},
14+
resolveLoader: {
15+
fallback: path.join(directory, 'node_modules'),
16+
},
17+
};
18+
};

examples/webpack/webpack.config.js

+4-16
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,11 @@
1-
var path = require('path');
1+
var common = require('../webpack.config');
22

3-
module.exports = {
4-
entry: './index.js',
5-
output: {
6-
path: 'bundle',
7-
filename: 'bundle.js',
8-
},
9-
devtool: 'cheap-eval-source-map',
10-
resolve: {
11-
fallback: path.join(__dirname, 'node_modules'),
12-
},
13-
resolveLoader: {
14-
fallback: path.join(__dirname, 'node_modules'),
15-
},
3+
module.exports = Object.assign({}, common(__dirname), {
164
module: {
175
loaders: [
186
{
197
test: /\.react.css$/,
20-
loader: 'babel-loader!react-css-components',
8+
loader: 'react-css-components',
219
},
2210
{
2311
test: /\.js$/,
@@ -26,4 +14,4 @@ module.exports = {
2614
}
2715
]
2816
}
29-
};
17+
});

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
"babylon": "^6.7.0",
5353
"invariant": "^2.2.1",
5454
"loader-utils": "^0.2.14",
55-
"object-assign": "^4.1.0",
5655
"postcss": "^5.0.19",
5756
"postcss-selector-parser": "^1.3.3"
5857
},
+43-29
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,44 @@
1-
import React from "react";
2-
import styles from "css";
3-
export function Label({
4-
variant = {},
5-
...props }) {
6-
let className = styles.Label;
7-
return React.createElement("div", { ...props, className
8-
});
9-
}
10-
export function Hint({
11-
variant = {},
12-
...props }) {
13-
let className = styles.Hint;
14-
return React.createElement("div", { ...props, className
15-
});
16-
}
17-
export function Paragraph({
18-
variant = {},
19-
...props }) {
20-
let className = styles.Paragraph;
21-
return React.createElement("div", { ...props, className
22-
});
23-
}
24-
export function X({
25-
variant = {},
26-
...props }) {
27-
let className = styles.X + (variant.hover ? ' ' + styles.X__hover : '');
28-
return React.createElement("div", { ...props, className
29-
});
1+
var React = require("react");
2+
3+
var styles = require("css");
4+
5+
function reconcileProps(props, className) {
6+
var nextProps = {};
7+
8+
for (var k in props) {
9+
if (k === 'variant') {
10+
continue;
11+
}
12+
13+
if (props.hasOwnProperty(k)) {
14+
nextProps[k] = props[k];
15+
}
16+
}
17+
18+
nextProps.className = className;
19+
return nextProps;
3020
}
21+
22+
module.exports.Label = function Label(props) {
23+
var variant = props.variant || {};
24+
var className = styles.Label;
25+
return React.createElement("div", reconcileProps(props, className));
26+
};
27+
28+
module.exports.Hint = function Hint(props) {
29+
var variant = props.variant || {};
30+
var className = styles.Hint;
31+
return React.createElement("div", reconcileProps(props, className));
32+
};
33+
34+
module.exports.Paragraph = function Paragraph(props) {
35+
var variant = props.variant || {};
36+
var className = styles.Paragraph;
37+
return React.createElement("div", reconcileProps(props, className));
38+
};
39+
40+
module.exports.X = function X(props) {
41+
var variant = props.variant || {};
42+
var className = styles.X + (variant.hover ? ' ' + styles.X__hover : '');
43+
return React.createElement("div", reconcileProps(props, className));
44+
};

src/__tests__/fixtures/custom-base.js

+25-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
1-
import React from "react";
2-
import styles from "css";
3-
export function Label({
4-
variant = {},
5-
...props }) {
6-
let className = styles.Label;
7-
return React.createElement("span", { ...props, className
8-
});
1+
var React = require("react");
2+
3+
var styles = require("css");
4+
5+
function reconcileProps(props, className) {
6+
var nextProps = {};
7+
8+
for (var k in props) {
9+
if (k === 'variant') {
10+
continue;
11+
}
12+
13+
if (props.hasOwnProperty(k)) {
14+
nextProps[k] = props[k];
15+
}
16+
}
17+
18+
nextProps.className = className;
19+
return nextProps;
920
}
21+
22+
module.exports.Label = function Label(props) {
23+
var variant = props.variant || {};
24+
var className = styles.Label;
25+
return React.createElement("span", reconcileProps(props, className));
26+
};
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
1-
import React from "react";
2-
import styles from "css";
3-
export function Label({
4-
variant = {},
5-
...props }) {
6-
let className = styles.Label + (variant.important ? ' ' + styles.Label__important : '') + (variant.shadow ? ' ' + styles.Label__shadow : '');
7-
return React.createElement("div", { ...props, className
8-
});
1+
var React = require("react");
2+
3+
var styles = require("css");
4+
5+
function reconcileProps(props, className) {
6+
var nextProps = {};
7+
8+
for (var k in props) {
9+
if (k === 'variant') {
10+
continue;
11+
}
12+
13+
if (props.hasOwnProperty(k)) {
14+
nextProps[k] = props[k];
15+
}
16+
}
17+
18+
nextProps.className = className;
19+
return nextProps;
920
}
21+
22+
module.exports.Label = function Label(props) {
23+
var variant = props.variant || {};
24+
var className = styles.Label + (variant.important ? ' ' + styles.Label__important : '') + (variant.shadow ? ' ' + styles.Label__shadow : '');
25+
return React.createElement("div", reconcileProps(props, className));
26+
};
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
1-
import React from "react";
2-
import styles from "css";
3-
export function Label({
4-
variant = {},
5-
...props }) {
6-
let className = styles.Label + (variant.custom ? ' ' + styles.Label__custom : '');
7-
return React.createElement("div", { ...props, className
8-
});
1+
var React = require("react");
2+
3+
var styles = require("css");
4+
5+
function reconcileProps(props, className) {
6+
var nextProps = {};
7+
8+
for (var k in props) {
9+
if (k === 'variant') {
10+
continue;
11+
}
12+
13+
if (props.hasOwnProperty(k)) {
14+
nextProps[k] = props[k];
15+
}
16+
}
17+
18+
nextProps.className = className;
19+
return nextProps;
920
}
21+
22+
module.exports.Label = function Label(props) {
23+
var variant = props.variant || {};
24+
var className = styles.Label + (variant.custom ? ' ' + styles.Label__custom : '');
25+
return React.createElement("div", reconcileProps(props, className));
26+
};
+25-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
1-
import React from "react";
2-
import styles from "css";
3-
export function Label({
4-
variant = {},
5-
...props }) {
6-
let className = styles.Label + (variant.important ? ' ' + styles.Label__important : '');
7-
return React.createElement("div", { ...props, className
8-
});
1+
var React = require("react");
2+
3+
var styles = require("css");
4+
5+
function reconcileProps(props, className) {
6+
var nextProps = {};
7+
8+
for (var k in props) {
9+
if (k === 'variant') {
10+
continue;
11+
}
12+
13+
if (props.hasOwnProperty(k)) {
14+
nextProps[k] = props[k];
15+
}
16+
}
17+
18+
nextProps.className = className;
19+
return nextProps;
920
}
21+
22+
module.exports.Label = function Label(props) {
23+
var variant = props.variant || {};
24+
var className = styles.Label + (variant.important ? ' ' + styles.Label__important : '');
25+
return React.createElement("div", reconcileProps(props, className));
26+
};
+27-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
1-
import React from "react";
2-
import styles from "css";
3-
import { Label as Label__Base } from "lib";
4-
export function Label({
5-
variant = {},
6-
...props }) {
7-
let className = styles.Label;
8-
return React.createElement(Label__Base, { ...props, className
9-
});
1+
var React = require("react");
2+
3+
var styles = require("css");
4+
5+
var Label__Base = require("lib").Label;
6+
7+
function reconcileProps(props, className) {
8+
var nextProps = {};
9+
10+
for (var k in props) {
11+
if (k === 'variant') {
12+
continue;
13+
}
14+
15+
if (props.hasOwnProperty(k)) {
16+
nextProps[k] = props[k];
17+
}
18+
}
19+
20+
nextProps.className = className;
21+
return nextProps;
1022
}
23+
24+
module.exports.Label = function Label(props) {
25+
var variant = props.variant || {};
26+
var className = styles.Label;
27+
return React.createElement(Label__Base, reconcileProps(props, className));
28+
};
+27-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
1-
import React from "react";
2-
import styles from "css";
3-
import { default as Label__Base } from "somelib/Label";
4-
export function Label({
5-
variant = {},
6-
...props }) {
7-
let className = styles.Label;
8-
return React.createElement(Label__Base, { ...props, className
9-
});
1+
var React = require("react");
2+
3+
var styles = require("css");
4+
5+
var Label__Base = require("somelib/Label").default;
6+
7+
function reconcileProps(props, className) {
8+
var nextProps = {};
9+
10+
for (var k in props) {
11+
if (k === 'variant') {
12+
continue;
13+
}
14+
15+
if (props.hasOwnProperty(k)) {
16+
nextProps[k] = props[k];
17+
}
18+
}
19+
20+
nextProps.className = className;
21+
return nextProps;
1022
}
23+
24+
module.exports.Label = function Label(props) {
25+
var variant = props.variant || {};
26+
var className = styles.Label;
27+
return React.createElement(Label__Base, reconcileProps(props, className));
28+
};

src/__tests__/fixtures/only-pseudo.js

+25-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
1-
import React from "react";
2-
import styles from "css";
3-
export function Label({
4-
variant = {},
5-
...props }) {
6-
let className = styles.Label + (variant.hover ? ' ' + styles.Label__hover : '');
7-
return React.createElement("div", { ...props, className
8-
});
1+
var React = require("react");
2+
3+
var styles = require("css");
4+
5+
function reconcileProps(props, className) {
6+
var nextProps = {};
7+
8+
for (var k in props) {
9+
if (k === 'variant') {
10+
continue;
11+
}
12+
13+
if (props.hasOwnProperty(k)) {
14+
nextProps[k] = props[k];
15+
}
16+
}
17+
18+
nextProps.className = className;
19+
return nextProps;
920
}
21+
22+
module.exports.Label = function Label(props) {
23+
var variant = props.variant || {};
24+
var className = styles.Label + (variant.hover ? ' ' + styles.Label__hover : '');
25+
return React.createElement("div", reconcileProps(props, className));
26+
};

0 commit comments

Comments
 (0)