-
Notifications
You must be signed in to change notification settings - Fork 208
Fixed nested themes not being republished on outer theme changes #363
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,11 @@ class ThemeProvider extends React.Component { | |
|
||
setOuterTheme = theme => { | ||
this.outerTheme = theme | ||
this.publishTheme() | ||
} | ||
|
||
publishTheme(theme) { | ||
this.broadcast.setState(this.getTheme(theme)) | ||
} | ||
|
||
componentDidMount() { | ||
|
@@ -53,13 +58,12 @@ class ThemeProvider extends React.Component { | |
// set broadcast state by merging outer theme with own | ||
if (this.context[CHANNEL]) { | ||
this.setOuterTheme(this.context[CHANNEL].getState()) | ||
this.broadcast.setState(this.getTheme()) | ||
} | ||
} | ||
|
||
componentWillReceiveProps(nextProps) { | ||
if (this.props.theme !== nextProps.theme) { | ||
this.broadcast.setState(this.getTheme(nextProps.theme)) | ||
this.publishTheme(nextProps.theme) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pardon my ignorance, but how has this made an effectual change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh, this part is actually not a fix of any sorts, i just have extracted it to separate method so it would be easier to reuse it in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, thanks for clarifying. |
||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain why this was removed? It seems unrelated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
publishTheme method is doing a setState and setOuterTheme uses now publishTheme under the hood
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is the real fix, and
publishTheme
is only incidentally changed.This line was setting the state with no argument, which defaults to the
props.theme
hereglamorous/src/theme-provider.js
Line 21 in cb6de3a
A lot of the theming work was done by @vesparny, so if I'm wrong hopefully he can correct me. 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this part of defaulting to
this.props.theme
is a making a control flow a little bit iffy but I left this part untouched. Personally I would prefer explicit arguments, so thatpublishTheme
would always have to receivegetTheme
's result as argument which in turn would always be called withthis.props.theme
if necessary.Also I've noticed a different small issue too - broadcast is initialized as:
but that gives it untrue initialState in case of nested ThemeProvider. I think creation of the
broadcast
should be delayed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure I follow, but to be clear, are you suggesting moving it to something like
componentWillMount
? With this PR, the theme that was (possibly) merged with the outer theme is now going to be set properly insidecomponentWillMount()
, so that untrue initial state won't really ever be in effect.Did I follow your point correctly? If not any clarification would be great. 🙌
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that was exactly my point :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, thanks! It makes sense to me. Maybe you want to do that as a follow-up PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing, would prefer to create it once we settle on this one to avoid potential conflicts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the discussion here!