Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 28 additions & 23 deletions src/components/themr.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export default (componentName, localTheme, options = {}) => ThemedComponent => {

constructor(...args) {
super(...args)
this.theme_ = this.calcTheme(this.props)
this.theme_ = this.calcTheme()
}

getWrappedInstance() {
Expand All @@ -97,8 +97,8 @@ export default (componentName, localTheme, options = {}) => ThemedComponent => {
return this.refs.wrappedInstance
}

getNamespacedTheme(props) {
const { themeNamespace, theme } = props
getNamespacedTheme() {
const { themeNamespace, theme } = this.props
if (!themeNamespace) return theme

if (themeNamespace && !theme) {
Expand All @@ -119,8 +119,9 @@ export default (componentName, localTheme, options = {}) => ThemedComponent => {
)
}

getThemeNotComposed(props) {
if (props.theme) return this.getNamespacedTheme(props)
getThemeNotComposed() {
const { theme } = this.props
if (theme) return this.getNamespacedTheme()
if (config.localTheme) return config.localTheme
return this.getContextTheme()
}
Expand All @@ -131,34 +132,38 @@ export default (componentName, localTheme, options = {}) => ThemedComponent => {
: {}
}

getTheme(props) {
return props.composeTheme === COMPOSE_SOFTLY
getTheme() {
const { composeTheme } = this.props
return composeTheme === COMPOSE_SOFTLY
? {
...this.getContextTheme(),
...config.localTheme,
...this.getNamespacedTheme(props)
}
...this.getContextTheme(),
...config.localTheme,
...this.getNamespacedTheme()
}
: themeable(
themeable(this.getContextTheme(), config.localTheme),
this.getNamespacedTheme(props)
)
themeable(this.getContextTheme(), config.localTheme),
this.getNamespacedTheme()
)
}

calcTheme(props) {
const { composeTheme } = props
calcTheme() {
const { composeTheme } = this.props
return composeTheme
? this.getTheme(props)
: this.getThemeNotComposed(props)
? this.getTheme()
: this.getThemeNotComposed()
}

componentWillReceiveProps(nextProps) {
shouldComponentUpdate(prevProps) {
const { composeTheme, theme, themeNamespace } = this.props
if (
nextProps.composeTheme !== this.props.composeTheme ||
nextProps.theme !== this.props.theme ||
nextProps.themeNamespace !== this.props.themeNamespace
composeTheme !== prevProps.composeTheme ||
theme !== prevProps.theme ||
themeNamespace !== prevProps.themeNamespace
) {
this.theme_ = this.calcTheme(nextProps)
this.theme_ = this.calcTheme()
return true
}
return false
}

render() {
Expand Down