aboutsummaryrefslogtreecommitdiff
path: root/src/services/theme_data
diff options
context:
space:
mode:
authorHenry Jameson <me@hjkos.com>2024-02-27 00:07:45 +0200
committerHenry Jameson <me@hjkos.com>2024-02-27 00:07:45 +0200
commitef2c8f077dee094c533ba2bdb0c8694a21760868 (patch)
treeab349d0364bdb5bfd358358553fdfc22d93b53f8 /src/services/theme_data
parentdc22386599c77fdd5a8b88ccfd167cff36d14c67 (diff)
refactor and optimize: now lazy rules are processed in chunks
Diffstat (limited to 'src/services/theme_data')
-rw-r--r--src/services/theme_data/theme_data_3.service.js33
1 files changed, 13 insertions, 20 deletions
diff --git a/src/services/theme_data/theme_data_3.service.js b/src/services/theme_data/theme_data_3.service.js
index 926988f7..05af9e17 100644
--- a/src/services/theme_data/theme_data_3.service.js
+++ b/src/services/theme_data/theme_data_3.service.js
@@ -148,10 +148,7 @@ export const init = (extraRuleset, ultimateBackgroundColor) => {
const staticVars = {}
const stacked = {}
const computed = {}
-
- const eagerRules = []
- const lazyRules = []
- const lazyPromises = []
+ const rules = []
const rulesetUnsorted = [
...Object.values(components)
@@ -188,11 +185,7 @@ export const init = (extraRuleset, ultimateBackgroundColor) => {
const virtualComponents = new Set(Object.values(components).filter(c => c.virtual).map(c => c.name))
- const processCombination = (combination, rules) => {
- const addRule = (rule) => {
- rules.push(rule)
- }
-
+ const processCombination = (combination) => {
const selector = ruleToSelector(combination, true)
const cssSelector = ruleToSelector(combination)
@@ -377,12 +370,15 @@ export const init = (extraRuleset, ultimateBackgroundColor) => {
}
})
- addRule({
+ const rule = {
dynamicVars,
selector: cssSelector,
...combination,
directives: computedDirectives
- })
+ }
+
+ rules.push(rule)
+ return rule
}
}
@@ -449,22 +445,19 @@ export const init = (extraRuleset, ultimateBackgroundColor) => {
const t1 = performance.now()
console.debug('Tree tranveral took ' + (t1 - t0) + ' ms')
- combinations.forEach((combination) => {
+ const result = combinations.map((combination) => {
if (combination.lazy) {
- lazyPromises.push(async () => processCombination(combination, lazyRules))
+ return async () => processCombination(combination)
} else {
- processCombination(combination, eagerRules)
+ return processCombination(combination)
}
- })
+ }).filter(x => x)
const t2 = performance.now()
console.debug('Eager processing took ' + (t2 - t1) + ' ms')
return {
- lazy: async () => {
- await Promise.all(lazyPromises.map(x => x()))
- return lazyRules
- },
- eager: eagerRules,
+ lazy: result.filter(x => typeof x === 'function'),
+ eager: result.filter(x => typeof x !== 'function'),
staticVars
}
}