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.

fix: infinite loop dasl-sync

+30 -63
+30 -63
src/components/transformer/output/bytes/dasl-sync/element.js
··· 28 28 * @template {{ id: string; updatedAt: string }} T 29 29 * @param {SignalReader<Uint8Array | undefined>} localCollection 30 30 * @param {SignalReader<Uint8Array | undefined>} remoteCollection 31 + * @param {{ saveLocal: (bytes: Uint8Array) => void, saveRemote: (bytes: Uint8Array) => Promise<void> }} sync 31 32 */ 32 - const state = (localCollection, remoteCollection) => { 33 + const state = (localCollection, remoteCollection, sync) => { 33 34 /** 34 35 * @typedef {{ container: Container<T> | { local: Container<T>; merged: { signal: SignalReader<Container<T> | undefined>; promise: Promise<Container<T>> } }; diverged: boolean; local: boolean; remote: boolean; }} State 35 36 */ ··· 94 95 if (diverged.local || diverged.remote) { 95 96 const promise = this.merge(l, r).then((c) => { 96 97 console.log("Merged:", c); 98 + const bytes = this.save(c); 99 + if (diverged.local) sync.saveLocal(bytes); 100 + if (diverged.remote) sync.saveRemote(bytes); 97 101 mergedSignal.set(c); 98 102 return c; 99 103 }); ··· 165 169 const facets = state( 166 170 local.facets.get, 167 171 remote.facets.collection, 172 + { 173 + saveLocal: this.putLocalFn("facets", local.facets), 174 + saveRemote: remote.facets.save, 175 + }, 168 176 ); 169 177 170 178 const playlistItems = state( 171 179 local.playlistItems.get, 172 180 remote.playlistItems.collection, 181 + { 182 + saveLocal: this.putLocalFn("playlistItems", local.playlistItems), 183 + saveRemote: remote.playlistItems.save, 184 + }, 173 185 ); 174 186 175 187 const themes = state( 176 188 local.themes.get, 177 189 remote.themes.collection, 190 + { 191 + saveLocal: this.putLocalFn("themes", local.themes), 192 + saveRemote: remote.themes.save, 193 + }, 178 194 ); 179 195 180 196 const tracks = state( 181 197 local.tracks.get, 182 198 remote.tracks.collection, 199 + { 200 + saveLocal: this.putLocalFn("tracks", local.tracks), 201 + saveRemote: remote.tracks.save, 202 + }, 183 203 ); 184 204 185 205 // Output manager ··· 208 228 ); 209 229 210 230 this.ready = () => true; 211 - 212 - // Effects 213 - // this.effect(async () => { 214 - // if (remote.facets.state() !== "loaded") return; 215 - // const s = facets(); 216 - // if (s.diverged) { 217 - // const bytes = this.save( 218 - // "merged" in s.container 219 - // ? await s.container.merged.promise 220 - // : s.container, 221 - // ); 222 - // local.facets.set(bytes); 223 - // this.putLocal("facets", bytes); 224 - // if (s.remote) remote.facets.save(bytes); 225 - // } 226 - // }); 227 - 228 - // this.effect(async () => { 229 - // if (remote.playlistItems.state() !== "loaded") return; 230 - // const s = playlistItems(); 231 - // if (s.diverged) { 232 - // const bytes = this.save( 233 - // "merged" in s.container 234 - // ? await s.container.merged.promise 235 - // : s.container, 236 - // ); 237 - // local.playlistItems.set(bytes); 238 - // this.putLocal("playlistItems", bytes); 239 - // if (s.remote) remote.playlistItems.save(bytes); 240 - // } 241 - // }); 242 - 243 - // this.effect(async () => { 244 - // if (remote.themes.state() !== "loaded") return; 245 - // const s = themes(); 246 - // if (s.diverged) { 247 - // const bytes = this.save( 248 - // "merged" in s.container 249 - // ? await s.container.merged.promise 250 - // : s.container, 251 - // ); 252 - // local.themes.set(bytes); 253 - // this.putLocal("themes", bytes); 254 - // if (s.remote) remote.themes.save(bytes); 255 - // } 256 - // }); 257 - 258 - // this.effect(async () => { 259 - // if (remote.tracks.state() !== "loaded") return; 260 - // const s = tracks(); 261 - // if (s.diverged) { 262 - // const bytes = this.save( 263 - // "merged" in s.container 264 - // ? await s.container.merged.promise 265 - // : s.container, 266 - // ); 267 - // local.tracks.set(bytes); 268 - // this.putLocal("tracks", bytes); 269 - // if (s.remote) remote.tracks.save(bytes); 270 - // } 271 - // }); 272 231 } 273 232 274 233 // DATA FUNCTIONS ··· 488 447 console.log("Bytes:", bytes); 489 448 await local.save(bytes); 490 449 }, 491 - state: computed(() => "loaded"), 450 + state: computed(() => { 451 + const c = container().container; 452 + 453 + /** @type {Container<T> | undefined} */ 454 + const cont = "merged" in c ? c.signal() : c; 455 + 456 + if (cont?.cid) return "loaded"; 457 + return "loading"; 458 + }), 492 459 }; 493 460 } 494 461