Skip to content

Commit 1eff8c3

Browse files
FezVrastagajus
authored andcommittedApr 20, 2017
fix: Make styles property always not enumerable (#231)
fixes #217
1 parent 7b1da9b commit 1eff8c3

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed
 

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"css",
1313
"modules"
1414
],
15-
"version": "4.0.3",
15+
"version": "4.0.4",
1616
"author": {
1717
"name": "Gajus Kuizinas",
1818
"email": "gajus@gajus.com",

‎src/extendReactClass.js

+10-13
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,34 @@ import renderNothing from './renderNothing';
1515
export default (Component: Object, defaultStyles: Object, options: Object) => {
1616
const WrappedComponent = class extends Component {
1717
render () {
18-
let propsChanged;
1918
let styles;
2019

21-
propsChanged = false;
20+
const hasDefaultstyles = _.isObject(defaultStyles);
2221

23-
if (this.props.styles) {
24-
styles = this.props.styles;
25-
} else if (_.isObject(defaultStyles)) {
22+
if (this.props.styles || hasDefaultstyles) {
2623
const props = Object.assign({}, this.props);
2724

25+
if (this.props.styles) {
26+
styles = this.props.styles;
27+
} else if (hasDefaultstyles) {
28+
styles = defaultStyles;
29+
delete this.props.styles;
30+
}
31+
2832
Object.defineProperty(props, 'styles', {
2933
configurable: true,
3034
enumerable: false,
31-
value: defaultStyles,
35+
value: styles,
3236
writable: false
3337
});
3438

3539
this.props = props;
36-
37-
propsChanged = true;
38-
styles = defaultStyles;
3940
} else {
4041
styles = {};
4142
}
4243

4344
const renderResult = super.render();
4445

45-
if (propsChanged) {
46-
delete this.props.styles;
47-
}
48-
4946
if (renderResult) {
5047
return linkClass(renderResult, styles, options);
5148
}

0 commit comments

Comments
 (0)