Add a function to initialise Regions & Markers #3123
Closed
juliancheal
started this conversation in
Ideas
Replies: 2 comments 2 replies
-
Have you considered creating those initial regions before subscribing to the region-created event? |
Beta Was this translation helpful? Give feedback.
0 replies
-
Hi @katspaugh thanks for your reply. I thought that's what I was doing already. Bellow is an except of my code. I load the regions from the db, and call this.wavesurfer.on('decode', () => {
this.loadRegions()
})
// More code here
this.regions.on('region-created', (region) => {
this.saveRegions(region.start, region.end, region.id)
}) |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm new to using Wavesurfer so this may not be a good idea 🙈
In my app I am saving regions (and markers) so that they are persistent. Then when the user loads the page the regions are still there. To do that I am creating new regions which I load from the database in the
wavesurfer.on('decode')
function. This is all seems to be working well, except:When creating new regions we're emitting
region-created
events in the saveRegion function.I tried unsubscribing from these events while I initalise the page using the
un
function. But someregion-created
events were still getting through.In my backend code I have checks to make sure we don't create duplicate events, but the main issue is it's creating unnecessary network requests and db lookups.
My thought was to add another function to the Regions class to initialise a set of regions and that function wouldn't emit any events, or at least create a way to pass a parameter to
addRegion
to suppress theregion-created
event.Before I attempted to create a PR, I thought I'd see if this is a wanted feature. Or maybe I've just not quite got the hang of wavesurfer and there is a better way to do what I wanted. Happy for feedback, comments, etc. :)
Beta Was this translation helpful? Give feedback.
All reactions