generated from uwu/neptune-template
-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
172 additions
and
71 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,26 @@ | ||
import { actions, store } from "@neptune"; | ||
import type { Album } from "neptune-types/tidal"; | ||
import { interceptPromise } from "../intercept/interceptPromise"; | ||
import { undefinedWarn } from "../undefinedError"; | ||
|
||
export class AlbumCache { | ||
private static readonly _cache: Record<number, Album> = {}; | ||
public static async get(albumId?: number) { | ||
if (albumId === undefined) return undefined; | ||
|
||
let mediaItem = this._cache[albumId]; | ||
if (mediaItem !== undefined) return mediaItem; | ||
|
||
const mediaItems: Record<number, Album> = store.getState().content.albums; | ||
for (const itemId in mediaItems) this._cache[itemId] = mediaItems[itemId]; | ||
|
||
if (this._cache[albumId] === undefined) { | ||
const album = await interceptPromise(() => actions.content.loadAlbum({ albumId }), ["content/LOAD_ALBUM_SUCCESS"], []) | ||
.then((res) => <Album>res?.[0].album) | ||
.catch(undefinedWarn("AlbumCache.get")); | ||
if (album !== undefined) this._cache[albumId] = album; | ||
} | ||
|
||
return this._cache[albumId]; | ||
} | ||
} |
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
File renamed without changes.
19 changes: 17 additions & 2 deletions
19
lib/interceptPromise.ts → lib/intercept/interceptPromise.ts
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
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
Oops, something went wrong.