Skip to content

Commit

Permalink
Avoid using window
Browse files Browse the repository at this point in the history
  • Loading branch information
kyoshino committed May 7, 2024
1 parent 5a942c4 commit cfee3ee
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/lib/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const waitForVisibility = (element) => {
}
});

window.requestAnimationFrame(() => {
globalThis.requestAnimationFrame(() => {
observer.observe(element);
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/lib/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
export const sleep = (ms = 1000) =>
new Promise((resolve) => {
window.setTimeout(() => {
globalThis.setTimeout(() => {
resolve(void 0);
}, ms);
});
2 changes: 1 addition & 1 deletion src/lib/storage/indexed-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default class IndexedDB {
*/
async #openDatabase(version) {
return new Promise((resolve) => {
const request = window.indexedDB.open(this.#databaseName, version);
const request = globalThis.indexedDB.open(this.#databaseName, version);

request.onupgradeneeded = () => {
request.result.createObjectStore(this.#storeName);
Expand Down
14 changes: 7 additions & 7 deletions src/lib/storage/local-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class LocalStorage {
* @throws {DOMException} When storage access is denied.
*/
static async set(key, value) {
window.localStorage.setItem(key, JSON.stringify(value));
globalThis.localStorage.setItem(key, JSON.stringify(value));
}

/**
Expand All @@ -22,7 +22,7 @@ export default class LocalStorage {
* @throws {DOMException} When storage access is denied.
*/
static async get(key) {
const cache = window.localStorage.getItem(key);
const cache = globalThis.localStorage.getItem(key);

return cache ? JSON.parse(cache) : null;
}
Expand All @@ -33,15 +33,15 @@ export default class LocalStorage {
* @throws {DOMException} When storage access is denied.
*/
static async delete(key) {
window.localStorage.removeItem(key);
globalThis.localStorage.removeItem(key);
}

/**
* Clear the storage.
* @throws {DOMException} When storage access is denied.
*/
static async clear() {
window.localStorage.clear();
globalThis.localStorage.clear();
}

/**
Expand All @@ -50,7 +50,7 @@ export default class LocalStorage {
* @throws {DOMException} When storage access is denied.
*/
static async keys() {
return Object.keys(window.localStorage);
return Object.keys(globalThis.localStorage);
}

/**
Expand All @@ -59,7 +59,7 @@ export default class LocalStorage {
* @throws {DOMException} When storage access is denied.
*/
static async values() {
return Object.values(window.localStorage).map((value) => JSON.parse(value));
return Object.values(globalThis.localStorage).map((value) => JSON.parse(value));
}

/**
Expand All @@ -68,6 +68,6 @@ export default class LocalStorage {
* @throws {DOMException} When storage access is denied.
*/
static async entries() {
return Object.entries(window.localStorage).map(([key, value]) => [key, JSON.parse(value)]);
return Object.entries(globalThis.localStorage).map(([key, value]) => [key, JSON.parse(value)]);
}
}

0 comments on commit cfee3ee

Please sign in to comment.