benwiley4000 / volca-sampler

Send a new sound to your volca sample!

Home Page:https://volcasampler.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Implement tab sync with storage events

benwiley4000 opened this issue · comments

Avoid data getting out of sync between open tabs by setting a value in localStorage that will fire an event in any other tabs with the app loaded.

In one tab we can do:

localStorage.setItem('sampleUpdateEvent', JSON.stringify({ sampleId, when: Date.now() }));

In other other tab we can do:

window.addEventListener('storage', (e) => {
  if (e.key === 'sampleUpdateEvent') {
    const { sampleId } = JSON.parse(e.newValue);
    // implement update logic for sampleId: grab new data from storage and put at top of recently edited list
  }
});