File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,26 +11,30 @@ import type {
1111 TagNameOrStyledElementType
1212} from './types'
1313
14+ const dynamicSheets = [ ]
15+ let sheetsToUpdate = { }
16+
17+ asap ( ( ) => {
18+ const sheetNames = Object . keys ( sheetsToUpdate )
19+ if ( sheetNames . length ) {
20+ sheetsToUpdate = { }
21+ sheetNames . forEach ( sheetName =>
22+ dynamicSheets [ Number ( sheetName ) ] . attach ( ) . link ( ) )
23+ }
24+ } )
25+
1426const createStyled = ( jss : Function ) => (
1527 baseStyles : BaseStylesType = { }
1628) : StyledType => {
1729 let staticSheet
1830 let dynamicSheet
19-
20- let dynamicCounter = 0
21-
22- asap ( ( ) => {
23- if ( dynamicCounter ) {
24- dynamicCounter = 0
25- dynamicSheet . attach ( ) . link ( )
26- }
27- } )
31+ let dynamicSheetName
2832
2933 const addRule = ( name : string , style : ComponentStyleType , data : Object ) => {
3034 if ( data ) {
3135 dynamicSheet . detach ( ) . addRule ( name , style )
3236 dynamicSheet . update ( name , data )
33- dynamicCounter ++
37+ sheetsToUpdate [ dynamicSheetName ] = true
3438 }
3539 else {
3640 staticSheet . addRule ( name , style )
@@ -47,6 +51,8 @@ const createStyled = (jss: Function) => (
4751 link : true ,
4852 meta : 'DynamicComponentSheet' ,
4953 } ) . attach ( )
54+ dynamicSheets . push ( dynamicSheet )
55+ dynamicSheetName = dynamicSheets . length - 1
5056 }
5157
5258 return { staticSheet, dynamicSheet}
You can’t perform that action at this time.
0 commit comments