forked from TWS/kalkutago
Add event handlers for updates to tracks
This commit is contained in:
parent
646eb60dc9
commit
9fc85d9db0
|
@ -29,8 +29,11 @@ export const state = reactive({
|
|||
})
|
||||
this.tracks = tracks
|
||||
})
|
||||
source.addEventListener('TrackAdded', ({ data }) => {
|
||||
const track: Track = JSON.parse(data)
|
||||
this.tracks = [track, ...this.tracks]
|
||||
})
|
||||
source.addEventListener('TickDropped', event => {
|
||||
console.log(event)
|
||||
const tick: Tick = JSON.parse(event.data)
|
||||
const tracks = this.tracks.map(track => {
|
||||
if (track.id === tick.track_id) {
|
||||
|
@ -40,6 +43,14 @@ export const state = reactive({
|
|||
})
|
||||
this.tracks = tracks
|
||||
})
|
||||
source.addEventListener('TrackDropped', ({ data }) => {
|
||||
const track: Track = JSON.parse(data)
|
||||
this.tracks = this.tracks.filter($track => $track.id !== track.id)
|
||||
})
|
||||
source.addEventListener('TrackChanged', ({ data }) => {
|
||||
const track: Track = JSON.parse(data)
|
||||
this.tracks = this.tracks.map($track => $track.id === track.id ? track : $track)
|
||||
})
|
||||
source.addEventListener('Lagged', event => {
|
||||
console.log(event)
|
||||
// Refresh the page, refetching the list of tracks and ticks
|
||||
|
|
Loading…
Reference in a new issue