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.

wip: dasl sync

+44 -10
+43 -9
src/components/transformer/output/bytes/dasl-sync/element.js
··· 28 28 const local = this.#localOutput.get; 29 29 30 30 /** 31 - * @template {{ id: string }} T 31 + * @template {{ id: string; updatedAt: string }} T 32 32 * @param {SignalReader<Uint8Array | undefined>} localCollection 33 33 * @param {SignalReader<Uint8Array | undefined>} remoteCollection 34 - * @returns {SignalReader<{ container: Container<T>; diverged: boolean; local: boolean; remote: boolean; }>} 34 + * @returns {SignalReader<{ container: Container<T> | { local: Container<T>; merged: { signal: SignalReader<Container<T>>; promise: Promise<Container<T>> } }; diverged: boolean; local: boolean; remote: boolean; }>} 35 35 */ 36 - const state = (localCollection, remoteCollection) => 37 - computed(() => { 36 + const state = (localCollection, remoteCollection) => { 37 + return computed(() => { 38 38 const lb = localCollection(); 39 39 const rb = remote.ready() ? remoteCollection() : undefined; 40 40 ··· 54 54 } 55 55 : { 56 56 container: { 57 - cid: "", 58 57 data: [], 59 58 inventory: { current: {}, removed: [] }, 60 59 }, ··· 67 66 } 68 67 69 68 const diverged = this.hasDiverged({ local: l, remote: r }); 69 + const mergedSignal = signal( 70 + /** @type {Container<T> | undefined} */ (undefined), 71 + ); 72 + 73 + let promise; 74 + 75 + if (diverged.local || diverged.remote) { 76 + promise = this.merge(l, r).then(mergedSignal.set).then( 77 + mergedSignal.get, 78 + ); 79 + } 70 80 71 81 return { 72 82 container: diverged.local || diverged.remote 73 - ? /* this.merge(l, r) */ l 83 + ? { local: l, merged: { promise, signal: mergedSignal.get } } 74 84 : r, 75 85 diverged: diverged.local || diverged.remote, 76 86 local: diverged.local, 77 87 remote: diverged.remote, 78 88 }; 79 89 }); 90 + }; 80 91 81 92 const facets = state( 82 93 computed(() => local()?.facets?.collection()), ··· 98 109 remote.tracks.collection, 99 110 ); 100 111 101 - this.facets = undefined; 112 + this.facets = { 113 + collection: computed(() => { 114 + const container = facets().container; 115 + 116 + if ("merged" in container) { 117 + return container.merged.signal() ?? container.local; 118 + } 119 + 120 + return container; 121 + }), 122 + reload: remote.facets.reload, 123 + 124 + /** @param {Facet[]} data */ 125 + save: async (data) => { 126 + let container = facets().container; 127 + 128 + if ("merged" in container) { 129 + container = await container.merged.promise; 130 + } 131 + 132 + container; 133 + }, 134 + }; 135 + 102 136 this.playlistItems = undefined; 103 137 this.themes = undefined; 104 138 this.tracks = undefined; ··· 135 169 // 🛠️ 136 170 137 171 /** 138 - * @template {{ id: string }} T 172 + * @template {{ id: string; updatedAt: string }} T 139 173 * @param {{ local: Container<T>, remote: Container<T> }} _ 140 174 * @returns {{ local: boolean, remote: boolean }} Which store needs updating? 141 175 */ ··· 237 271 } 238 272 239 273 /** 240 - * @template {{ id: string }} T 274 + * @template {{ id: string; updatedAt: string }} T 241 275 * @param {{ previous: Container<T> | undefined, collection: T[] }} _ 242 276 * @returns {Promise<Container<T>>} 243 277 */
+1 -1
src/components/transformer/output/bytes/dasl-sync/types.d.ts
··· 3 3 * CID of the inventory, 4 4 * which in turns represents the current state of the data. 5 5 */ 6 - cid: string; 6 + cid?: string; 7 7 data: T[]; 8 8 inventory: Inventory; 9 9 };