1- import asap from 'asap'
2-
31import styled from './styled'
2+ import sheetsObserver from './utils/sheetsObserver'
43
54import type {
65 BaseStylesType ,
@@ -11,30 +10,20 @@ import type {
1110 TagNameOrStyledElementType
1211} from './types'
1312
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- } )
13+ sheetsObserver . listen ( )
2514
2615const createStyled = ( jss : Function ) => (
2716 baseStyles : BaseStylesType = { }
2817) : StyledType => {
2918 let staticSheet
3019 let dynamicSheet
31- let dynamicSheetName
20+ let dynamicSheetId
3221
3322 const addRule = ( name : string , style : ComponentStyleType , data : Object ) => {
3423 if ( data ) {
3524 dynamicSheet . detach ( ) . addRule ( name , style )
3625 dynamicSheet . update ( name , data )
37- sheetsToUpdate [ dynamicSheetName ] = true
26+ sheetsObserver . update ( dynamicSheetId )
3827 }
3928 else {
4029 staticSheet . addRule ( name , style )
@@ -51,8 +40,7 @@ const createStyled = (jss: Function) => (
5140 link : true ,
5241 meta : 'DynamicComponentSheet' ,
5342 } ) . attach ( )
54- dynamicSheets . push ( dynamicSheet )
55- dynamicSheetName = dynamicSheets . length - 1
43+ dynamicSheetId = sheetsObserver . add ( dynamicSheet )
5644 }
5745
5846 return { staticSheet, dynamicSheet}
0 commit comments