Quick context: I'm displaying a "live" image slideshow, meaning as images are being displayed, users can upload images & those new images should display (eventually). This is "infinite", meaning I want to restart at the first image once all images have been emitted. New incoming images should go to the end of the queue & emit once I loop back to them.
I've come up with what I think is a dirty & incorrect solution that boils down to:
const srcArray = [-2, -1];
const userImageUpload$ = interval(2000).pipe(
tap((val) => srcArray.push(val))
).subscribe();
const liveImages$ = zip(interval(1000), from(srcArray)).pipe(
map(([a, b]) => b),
repeat()
).subscribe((val) => console.log("Image " + val));
Here we have a starting array of some "images". The userImageUpload$ represents the idea of new images incoming. When I get one I push it into the starting array. liveImages$ represents the values I want emitted. This technically works, but altering this shared global array feels bad and may lead to issues. Is there a good solution to do this all in one, possibly with the use of subjects? I'm having trouble coming up with a solution.