Skip to content

Commit

Permalink
fix: Make styles property always not enumerable (#231)
Browse files Browse the repository at this point in the history
fixes #217
  • Loading branch information
FezVrasta authored and gajus committed Apr 20, 2017
1 parent 7b1da9b commit 1eff8c3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"css",
"modules"
],
"version": "4.0.3",
"version": "4.0.4",
"author": {
"name": "Gajus Kuizinas",
"email": "[email protected]",
Expand Down
23 changes: 10 additions & 13 deletions src/extendReactClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,34 @@ import renderNothing from './renderNothing';
export default (Component: Object, defaultStyles: Object, options: Object) => {
const WrappedComponent = class extends Component {
render () {
let propsChanged;
let styles;

propsChanged = false;
const hasDefaultstyles = _.isObject(defaultStyles);

if (this.props.styles) {
styles = this.props.styles;
} else if (_.isObject(defaultStyles)) {
if (this.props.styles || hasDefaultstyles) {
const props = Object.assign({}, this.props);

if (this.props.styles) {
styles = this.props.styles;
} else if (hasDefaultstyles) {
styles = defaultStyles;
delete this.props.styles;
}

Object.defineProperty(props, 'styles', {
configurable: true,
enumerable: false,
value: defaultStyles,
value: styles,
writable: false
});

this.props = props;

propsChanged = true;
styles = defaultStyles;
} else {
styles = {};
}

const renderResult = super.render();

if (propsChanged) {
delete this.props.styles;
}

if (renderResult) {
return linkClass(renderResult, styles, options);
}
Expand Down

0 comments on commit 1eff8c3

Please sign in to comment.