A music player that connects to your cloud/distributed storage.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

chore: output fallback element improvements

+12 -46
+12 -46
src/components/configurator/output-fallback/element.js
··· 2 2 import { batch, computed, signal } from "@common/signal.js"; 3 3 4 4 /** 5 - * @import {Facet, Playlist, Theme, Track} from "@definitions/types.d.ts" 6 5 * @import {OutputManagerDeputy, OutputElement} from "@components/output/types.d.ts" 7 6 */ 8 7 ··· 19 18 * 20 19 * Checks child output elements in order and delegates 21 20 * to the first one whose `.ready()` signal returns `true`. 22 - * If none are ready, falls back to in-memory storage. 23 21 * 24 22 * @implements {OutputManagerDeputy} 25 23 */ ··· 33 31 const manager = { 34 32 facets: { 35 33 collection: computed(() => { 36 - const out = this.activeOutput(); 37 - if (out) return out.facets.collection(); 38 - return this.#memory.facets.value; 34 + return this.activeOutput()?.facets.collection() ?? []; 39 35 }), 40 36 reload: () => { 41 37 const out = this.activeOutput(); ··· 43 39 return Promise.resolve(); 44 40 }, 45 41 save: async (newFacets) => { 46 - const out = this.activeOutput(); 47 - if (out) return await out.facets.save(newFacets); 48 - this.#memory.facets.value = newFacets; 42 + await Promise.all(this.#outputs.value.map((o) => o.facets.save(newFacets))); 49 43 }, 50 44 state: computed(() => { 51 - const out = this.activeOutput(); 52 - if (out) return out.facets.state(); 53 - return this.#setupFinished.value ? "loaded" : "sleeping"; 45 + return this.activeOutput()?.facets.state() ?? "sleeping"; 54 46 }), 55 47 }, 56 48 playlists: { 57 49 collection: computed(() => { 58 - const out = this.activeOutput(); 59 - if (out) return out.playlists.collection(); 60 - return this.#memory.playlists.value; 50 + return this.activeOutput()?.playlists.collection() ?? []; 61 51 }), 62 52 reload: () => { 63 53 const out = this.activeOutput(); ··· 65 55 return Promise.resolve(); 66 56 }, 67 57 save: async (newPlaylists) => { 68 - const out = this.activeOutput(); 69 - if (out) return await out.playlists.save(newPlaylists); 70 - this.#memory.playlists.value = newPlaylists; 58 + await Promise.all(this.#outputs.value.map((o) => o.playlists.save(newPlaylists))); 71 59 }, 72 60 state: computed(() => { 73 - const out = this.activeOutput(); 74 - if (out) return out.playlists.state(); 75 - return this.#setupFinished.value ? "loaded" : "sleeping"; 61 + return this.activeOutput()?.playlists.state() ?? "sleeping"; 76 62 }), 77 63 }, 78 64 themes: { 79 65 collection: computed(() => { 80 - const out = this.activeOutput(); 81 - if (out) return out.themes.collection(); 82 - return this.#memory.themes.value; 66 + return this.activeOutput()?.themes.collection() ?? []; 83 67 }), 84 68 reload: () => { 85 69 const out = this.activeOutput(); ··· 87 71 return Promise.resolve(); 88 72 }, 89 73 save: async (newThemes) => { 90 - const out = this.activeOutput(); 91 - if (out) return await out.themes.save(newThemes); 92 - this.#memory.themes.value = newThemes; 74 + await Promise.all(this.#outputs.value.map((o) => o.themes.save(newThemes))); 93 75 }, 94 76 state: computed(() => { 95 - const out = this.activeOutput(); 96 - if (out) return out.themes.state(); 97 - return this.#setupFinished.value ? "loaded" : "sleeping"; 77 + return this.activeOutput()?.themes.state() ?? "sleeping"; 98 78 }), 99 79 }, 100 80 tracks: { 101 81 collection: computed(() => { 102 - const out = this.activeOutput(); 103 - if (out) return out.tracks.collection(); 104 - return this.#memory.tracks.value; 82 + return this.activeOutput()?.tracks.collection() ?? []; 105 83 }), 106 84 reload: () => { 107 85 const out = this.activeOutput(); ··· 109 87 return Promise.resolve(); 110 88 }, 111 89 save: async (newTracks) => { 112 - const out = this.activeOutput(); 113 - if (out) return await out.tracks.save(newTracks); 114 - this.#memory.tracks.value = newTracks; 90 + await Promise.all(this.#outputs.value.map((o) => o.tracks.save(newTracks))); 115 91 }, 116 92 state: computed(() => { 117 - const out = this.activeOutput(); 118 - if (out) return out.tracks.state(); 119 - return this.#setupFinished.value ? "loaded" : "sleeping"; 93 + return this.activeOutput()?.tracks.state() ?? "sleeping"; 120 94 }), 121 95 }, 122 96 ··· 133 107 134 108 // SIGNALS 135 109 136 - #memory = { 137 - facets: signal(/** @type {Facet[]} */ ([])), 138 - playlists: signal(/** @type {Playlist[]} */ ([])), 139 - themes: signal(/** @type {Theme[]} */ ([])), 140 - tracks: signal(/** @type {Track[]} */ ([])), 141 - }; 142 - 143 110 #outputs = signal(/** @type {Output[]} */ ([])); 144 111 #setupFinished = signal(false); 145 112 ··· 150 117 */ 151 118 activeOutput = computed(() => { 152 119 const outputs = this.#outputs.value; 153 - // TODO: Not sure if this will cause a signal change too often. 154 120 for (const output of outputs) { 155 121 if (output.ready()) return output; 156 122 }