@@ -10,10 +10,26 @@ const DEFAULT_OPTIONS = {
10
10
withRef : false
11
11
}
12
12
13
+ const THEMR_CONFIG = typeof Symbol !== 'undefined' ?
14
+ Symbol ( 'THEMR_CONFIG' ) :
15
+ '__REACT_CSS_THEMR_CONFIG__'
16
+
13
17
export default ( componentName , localTheme , options = { } ) => ( ThemedComponent ) => {
14
18
const { composeTheme : optionComposeTheme , withRef : optionWithRef } = { ...DEFAULT_OPTIONS , ...options }
15
19
validateComposeOption ( optionComposeTheme )
16
- return class Themed extends Component {
20
+
21
+ let config = ThemedComponent [ THEMR_CONFIG ]
22
+ if ( config && config . componentName === componentName ) {
23
+ config . localTheme = themeable ( config . localTheme , localTheme )
24
+ return ThemedComponent
25
+ }
26
+
27
+ config = {
28
+ componentName,
29
+ localTheme
30
+ }
31
+
32
+ class Themed extends Component {
17
33
static displayName = `Themed ${ ThemedComponent . name } ` ;
18
34
19
35
static contextTypes = {
@@ -54,20 +70,20 @@ export default (componentName, localTheme, options = {}) => (ThemedComponent) =>
54
70
55
71
getThemeNotComposed ( ) {
56
72
if ( this . props . theme ) return this . getNamespacedTheme ( )
57
- if ( localTheme ) return localTheme
73
+ if ( config . localTheme ) return config . localTheme
58
74
return this . getContextTheme ( )
59
75
}
60
76
61
77
getContextTheme ( ) {
62
78
return this . context . themr
63
- ? this . context . themr . theme [ componentName ]
79
+ ? this . context . themr . theme [ config . componentName ]
64
80
: { }
65
81
}
66
82
67
83
getTheme ( ) {
68
84
return this . props . composeTheme === COMPOSE_SOFTLY
69
- ? { ...this . getContextTheme ( ) , ...localTheme , ...this . getNamespacedTheme ( ) }
70
- : themeable ( themeable ( this . getContextTheme ( ) , localTheme ) , this . getNamespacedTheme ( ) )
85
+ ? { ...this . getContextTheme ( ) , ...config . localTheme , ...this . getNamespacedTheme ( ) }
86
+ : themeable ( themeable ( this . getContextTheme ( ) , config . localTheme ) , this . getNamespacedTheme ( ) )
71
87
}
72
88
73
89
render ( ) {
@@ -94,6 +110,10 @@ export default (componentName, localTheme, options = {}) => (ThemedComponent) =>
94
110
return renderedElement
95
111
}
96
112
}
113
+
114
+ Themed [ THEMR_CONFIG ] = config
115
+
116
+ return Themed
97
117
}
98
118
99
119
export function themeable ( style = { } , theme ) {
0 commit comments