Skip to content

Commit

Permalink
Less nesting
Browse files Browse the repository at this point in the history
  • Loading branch information
allartk committed Jun 29, 2022
1 parent 8de958e commit 6846961
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/TileManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ export function openTilesDataBase(): Promise<IDBPDatabase> {
* ```
*/
export async function getStorageLength(): Promise<number> {
return (await openTilesDataBase()).count(tileStoreName);
const db = await openTilesDataBase();
return db.count(tileStoreName);
}

/**
Expand All @@ -65,11 +66,8 @@ export async function getStorageLength(): Promise<number> {
*/
export async function getStorageInfo(urlTemplate: string): Promise<TileInfo[]> {
const range = IDBKeyRange.only(urlTemplate);
return (await openTilesDataBase()).getAllFromIndex(
tileStoreName,
urlTemplateIndex,
range
);
const db = await openTilesDataBase();
return db.getAllFromIndex(tileStoreName, urlTemplateIndex, range);
}

/**
Expand All @@ -80,12 +78,11 @@ export async function getStorageInfo(urlTemplate: string): Promise<TileInfo[]> {
* ```
*/
export async function downloadTile(tileUrl: string): Promise<Blob> {
return fetch(tileUrl).then((response) => {
if (!response.ok) {
throw new Error(`Request failed with status ${response.statusText}`);
}
return response.blob();
});
const response = await fetch(tileUrl);
if (!response.ok) {
throw new Error(`Request failed with status ${response.statusText}`);
}
return response.blob();
}
/**
* @example
Expand All @@ -97,7 +94,8 @@ export async function saveTile(
tileInfo: TileInfo,
blob: Blob
): Promise<IDBValidKey> {
return (await openTilesDataBase()).put(tileStoreName, {
const db = await openTilesDataBase();
return db.put(tileStoreName, {
blob,
...tileInfo,
});
Expand Down Expand Up @@ -188,7 +186,8 @@ export function getStoredTilesAsJson(
* Remove tile by key
*/
export async function removeTile(key: string): Promise<void> {
return (await openTilesDataBase()).delete(tileStoreName, key);
const db = await openTilesDataBase();
return db.delete(tileStoreName, key);
}

/**
Expand Down

0 comments on commit 6846961

Please sign in to comment.