-
-
Notifications
You must be signed in to change notification settings - Fork 544
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from SkalskiP/image_loading
Image loading queuing
- Loading branch information
Showing
6 changed files
with
112 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
export class ImageLoadManager { | ||
|
||
private static queue: (() => Promise<any>)[] = []; | ||
private static isRunning: boolean = false; | ||
|
||
public static add(fx: Promise<any>) { | ||
ImageLoadManager.queue.push(async () => await fx); | ||
} | ||
|
||
public static run() { | ||
setTimeout(() => ImageLoadManager.runQueue(), 10); | ||
} | ||
|
||
public static async runQueue() { | ||
if (!ImageLoadManager.isRunning) { | ||
ImageLoadManager.isRunning = true; | ||
await ImageLoadManager.runTasks(); | ||
ImageLoadManager.isRunning = false; | ||
} | ||
} | ||
|
||
private static async runTasks() { | ||
while (ImageLoadManager.queue.length > 0) { | ||
const fx = ImageLoadManager.queue.shift(); | ||
await fx(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 6 additions & 6 deletions
12
src/views/EditorView/SideNavigationBar/ImagesList/ImagesList.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters