Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit 6b164d9

Browse files
committed
feat(build-in-helper): sync to async
1 parent 1878dce commit 6b164d9

File tree

3 files changed

+7
-25
lines changed

3 files changed

+7
-25
lines changed

src/core/method/create-build-in-helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ async function processStyleSheets() {
2626
isProcessing = false;
2727
}
2828

29-
export function createBuildIn(): void {
29+
export async function createBuildIn(): Promise<void> {
3030
if (typeof globalStyleSheetPromise === 'undefined') createGlobalStyleSheetPromise();
3131
if (!isProcessing && styleSheetQueue.length > 0) {
3232
isProcessing = true;

src/core/method/global-build-in-helper.ts

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,18 @@ import { buildIn, isDevelopment } from '../../_internal';
22

33
let resolveGlobalStyleSheet: (value: [string, string?]) => void;
44
let globalStyleSheetPromise: Promise<[string, string?]>;
5-
const styleSheetQueue: [string, string?][] = [];
6-
let isProcessing = false;
75

86
function createGlobalStyleSheetPromise() {
97
globalStyleSheetPromise = new Promise<[string, string?]>(resolve => {
10-
resolveGlobalStyleSheet = (value: [string, string?]) => {
11-
styleSheetQueue.push(value);
12-
resolve(value);
13-
};
8+
resolveGlobalStyleSheet = resolve;
149
});
1510
}
1611

17-
async function executeBuildIn(styleSheet: string, option?: string): Promise<void> {
18-
if (!isDevelopment && styleSheet) buildIn(styleSheet, option);
19-
}
20-
21-
async function processStyleSheets() {
22-
while (styleSheetQueue.length > 0) {
23-
const [styleSheet, option] = styleSheetQueue.shift() as [string, string?];
24-
await executeBuildIn(styleSheet, option);
25-
}
26-
isProcessing = false;
27-
}
28-
29-
export function globalBuildIn(): void {
12+
export async function globalBuildIn(): Promise<void> {
3013
if (typeof globalStyleSheetPromise === 'undefined') createGlobalStyleSheetPromise();
31-
if (!isProcessing && styleSheetQueue.length > 0) {
32-
isProcessing = true;
33-
processStyleSheets();
34-
}
14+
const [styleSheet, option] = await globalStyleSheetPromise;
15+
if (!isDevelopment && styleSheet) buildIn(styleSheet, option);
16+
createGlobalStyleSheetPromise();
3517
}
3618

3719
export { resolveGlobalStyleSheet, globalStyleSheetPromise, createGlobalStyleSheetPromise };

src/core/method/set-build-in-helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ async function processStyleSheets() {
2626
isProcessing = false;
2727
}
2828

29-
export function setBuildIn(): void {
29+
export async function setBuildIn(): Promise<void> {
3030
if (typeof globalStyleSheetPromise === 'undefined') createGlobalStyleSheetPromise();
3131
if (!isProcessing && styleSheetQueue.length > 0) {
3232
isProcessing = true;

0 commit comments

Comments
 (0)