Skip to content

Commit

Permalink
Merge pull request #1721 from oliviertassinari/hot-fix
Browse files Browse the repository at this point in the history
[ContextPure] Fix broken style property
  • Loading branch information
shaurya947 committed Sep 25, 2015
2 parents 1963003 + 29d0167 commit 77708f6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/buttons/flat-button-label.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const FlatButtonLabel = React.createClass({
this.setState({muiTheme: newMuiTheme});
},

static: {
statics: {
getRelevantContextKeys(muiTheme) {
return {
spacingDesktopGutterLess: muiTheme.rawTheme.spacing.desktopGutterLess,
Expand All @@ -57,7 +57,7 @@ const FlatButtonLabel = React.createClass({
style,
} = this.props;

const contextKeys = this.getRelevantContextKeys(this.state.muiTheme);
const contextKeys = this.constructor.getRelevantContextKeys(this.state.muiTheme);

const mergedRootStyles = Styles.mergeAndPrefix({
position: 'relative',
Expand Down
2 changes: 1 addition & 1 deletion src/card/card-expandable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const CardExpandable = React.createClass({
],

getStyles() {
const contextKeys = this.getRelevantContextKeys(this.state.muiTheme);
const contextKeys = this.constructor.getRelevantContextKeys(this.state.muiTheme);

const directionStyle = contextKeys.isRtl ? {
left: 4,
Expand Down
28 changes: 19 additions & 9 deletions src/mixins/context-pure.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,25 @@ module.exports = {

//Don't update if state, prop, and context are equal
shouldComponentUpdate(nextProps, nextState, nextContext) {
const staticTheme = this.context.muiTheme && this.context.muiTheme.static;
const isExactlyOneThemeUndefined = (!this.context.muiTheme && nextContext.muiTheme) || (this.context.muiTheme && !nextContext.muiTheme);

return (
!shallowEqual(this.props, nextProps) ||
!shallowEqual(this.state, nextState) ||
isExactlyOneThemeUndefined ||
(!staticTheme && !relevantContextKeysEqual(this.constructor, this.context.muiTheme, nextContext.muiTheme))
);

//If either the props or state have changed, component should update
if(!shallowEqual(this.props, nextProps) || !shallowEqual(this.state, nextState)) {
return true;
}

//If current theme and next theme are both undefined, do not update
if(!this.context.muiTheme && !nextContext.muiTheme) {
return false;
}

//If both themes exist, compare keys only if current theme is not static
if(this.context.muiTheme && nextContext.muiTheme) {
return !this.context.muiTheme.static &&
!relevantContextKeysEqual(this.constructor, this.context.muiTheme, nextContext.muiTheme);
}

//At this point it is guaranteed that exactly one theme is undefined so simply update
return true;
},

};
4 changes: 2 additions & 2 deletions src/text-field.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const TextField = React.createClass({

statics: {
getRelevantContextKeys(muiTheme) {
const textFieldTheme = this.state.muiTheme.textField
const textFieldTheme = muiTheme.textField

return {
floatingLabelColor: textFieldTheme.floatingLabelColor,
Expand Down Expand Up @@ -149,7 +149,7 @@ const TextField = React.createClass({
hintColor,
errorColor,
isRtl,
} = this.getRelevantContextKeys(this.state.muiTheme);
} = this.constructor.getRelevantContextKeys(this.state.muiTheme);

let styles = {
root: {
Expand Down

0 comments on commit 77708f6

Please sign in to comment.