Skip to content

Commit 4f29c6a

Browse files
author
Travis Lawrence
committed
Cleanup preloading
1 parent 3ce9180 commit 4f29c6a

2 files changed

Lines changed: 8 additions & 12 deletions

File tree

public/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"name": "Astronomy Picture of the Day APOD by The Trav",
55
"short_name": "APOD by The Trav",
66
"description": "Displays the Astronomy Picture of the Day (APOD) and allows you to review similar images of planets, stars, galaxies and nebulas",
7-
"version": "3.0.9",
7+
"version": "3.1.0",
88

99
"browser_action": {
1010
"default_icon": "sun_icon.png",

src/utilities/preload-utility.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@ const RELOAD_THRESHOLD = 5;
88
export default class Preload {
99
constructor() {
1010
this.loadingCount = 0;
11-
this.currentIdx = 0;
1211
this.dates = [];
13-
this.responses = {};
12+
1413
chrome.storage.sync.get(["preloadResponse"], ({ preloadResponse }) => {
1514
if (preloadResponse) {
16-
this.dates.push(preloadResponse.date);
17-
this.responses[preloadResponse.date] = preloadResponse;
15+
this.dates.push(preloadResponse);
1816
}
1917
this.getImages();
2018
});
@@ -68,23 +66,21 @@ export default class Preload {
6866
chrome.storage.sync.set({
6967
preloadResponse: response
7068
});
71-
this.dates.push(response.date);
72-
this.responses[response.date] = response;
69+
this.dates.push(response);
7370
this.decreaseLoadCount();
7471
};
7572

7673
getPreloadImage = (bypassLoadCount = false) => {
77-
const dateKey = this.dates[this.currentIdx];
78-
this.currentIdx += 1;
74+
const response = this.dates.shift();
7975

8076
if (
8177
!bypassLoadCount &&
82-
this.dates.length - this.currentIdx <= RELOAD_THRESHOLD &&
83-
this.loadingCount === 0
78+
this.dates.length <= RELOAD_THRESHOLD &&
79+
this.loadingCount < 3
8480
) {
8581
this.getImages();
8682
}
8783

88-
return this.responses[dateKey];
84+
return response;
8985
};
9086
}

0 commit comments

Comments
 (0)