try to apply lazy part in one go while still having chunked processing
This commit is contained in:
parent
9806eea12e
commit
1c23a16bac
@ -8,7 +8,7 @@ import { chunk } from 'lodash'
|
|||||||
|
|
||||||
export const generateTheme = async (input, callbacks) => {
|
export const generateTheme = async (input, callbacks) => {
|
||||||
const {
|
const {
|
||||||
onNewRule = (rule) => {},
|
onNewRule = (rule, isLazy) => {},
|
||||||
onLazyFinished = () => {},
|
onLazyFinished = () => {},
|
||||||
onEagerFinished = () => {}
|
onEagerFinished = () => {}
|
||||||
} = callbacks
|
} = callbacks
|
||||||
@ -38,9 +38,9 @@ export const generateTheme = async (input, callbacks) => {
|
|||||||
parts[1],
|
parts[1],
|
||||||
'}'
|
'}'
|
||||||
].join('')
|
].join('')
|
||||||
onNewRule(newRule)
|
onNewRule(newRule, false)
|
||||||
} else {
|
} else {
|
||||||
onNewRule(rule)
|
onNewRule(rule, false)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
onEagerFinished()
|
onEagerFinished()
|
||||||
@ -67,9 +67,9 @@ export const generateTheme = async (input, callbacks) => {
|
|||||||
parts[1],
|
parts[1],
|
||||||
'}'
|
'}'
|
||||||
].join('')
|
].join('')
|
||||||
onNewRule(newRule)
|
onNewRule(newRule, true)
|
||||||
} else {
|
} else {
|
||||||
onNewRule(rule)
|
onNewRule(rule, true)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// const t1 = performance.now()
|
// const t1 = performance.now()
|
||||||
@ -89,14 +89,24 @@ export const generateTheme = async (input, callbacks) => {
|
|||||||
|
|
||||||
export const applyTheme = async (input) => {
|
export const applyTheme = async (input) => {
|
||||||
const styleSheet = new CSSStyleSheet()
|
const styleSheet = new CSSStyleSheet()
|
||||||
document.adoptedStyleSheets = [styleSheet]
|
const lazyStyleSheet = new CSSStyleSheet()
|
||||||
|
|
||||||
const { lazyProcessFunc } = await generateTheme(
|
const { lazyProcessFunc } = await generateTheme(
|
||||||
input,
|
input,
|
||||||
{
|
{
|
||||||
onNewRule (rule) {
|
onNewRule (rule, isLazy) {
|
||||||
|
if (isLazy) {
|
||||||
|
lazyStyleSheet.insertRule(rule, 'index-max')
|
||||||
|
} else {
|
||||||
styleSheet.insertRule(rule, 'index-max')
|
styleSheet.insertRule(rule, 'index-max')
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
onEagerFinished () {
|
||||||
|
document.adoptedStyleSheets = [styleSheet]
|
||||||
|
},
|
||||||
|
onLazyFinished () {
|
||||||
|
document.adoptedStyleSheets = [styleSheet, lazyStyleSheet]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user