Skip to content

Commit

Permalink
Fixed nested themes not being republished on outer theme changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Andarist committed Dec 21, 2017
1 parent 47ec911 commit baf8f43
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions packages/emotion-theming/src/theme-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ class ThemeProvider extends Component {
if (this.context[channel] !== undefined) {
this.unsubscribeToOuterId = this.context[channel].subscribe(theme => {
this.outerTheme = theme
this.createBroadcast()
this.publish(this.props.theme)
})
return
}
this.broadcast = createBroadcast(this.getTheme(this.props.theme))

this.createBroadcast()
}

getChildContext() {
Expand All @@ -36,7 +40,7 @@ class ThemeProvider extends Component {

componentWillReceiveProps(nextProps) {
if (this.props.theme !== nextProps.theme) {
this.broadcast.publish(this.getTheme(nextProps.theme))
this.publish(nextProps.theme)
}
}

Expand All @@ -47,6 +51,10 @@ class ThemeProvider extends Component {
}
}

createBroadcast() {
this.broadcast = createBroadcast(this.getTheme(this.props.theme))
}

// Get the theme from the props, supporting both (outerTheme) => {} as well as object notation
getTheme(theme) {
if (typeof theme === 'function') {
Expand All @@ -71,6 +79,10 @@ class ThemeProvider extends Component {
return { ...this.outerTheme, ...theme }
}

publish(theme) {
this.broadcast.publish(this.getTheme(theme))
}

render() {
if (!this.props.children) {
return null
Expand Down

0 comments on commit baf8f43

Please sign in to comment.