Fix options update for multiple views with same URL

This commit is contained in:
Max Goodhart
2020-11-09 14:30:43 -08:00
parent c219656564
commit f49e52f09d
2 changed files with 13 additions and 11 deletions

View File

@@ -30,7 +30,6 @@ export default class StreamWindow extends EventEmitter {
this.backgroundView = null
this.overlayView = null
this.views = new Map()
this.viewsByURL = new Map()
this.viewActions = null
}
@@ -253,7 +252,6 @@ export default class StreamWindow extends EventEmitter {
}
const newViews = new Map()
const newViewsByURL = new Map()
for (const { box, view } of viewsToDisplay) {
const { content, x, y, w, h, spaces } = box
const pos = {
@@ -267,7 +265,6 @@ export default class StreamWindow extends EventEmitter {
view.send({ type: 'OPTIONS', options: getDisplayOptions(stream) })
view.send({ type: 'DISPLAY', pos, content })
newViews.set(view.state.context.id, view)
newViewsByURL.set(content.url, view)
}
for (const view of unusedViews) {
const browserView = view.state.context.view
@@ -275,7 +272,6 @@ export default class StreamWindow extends EventEmitter {
browserView.destroy()
}
this.views = newViews
this.viewsByURL = newViewsByURL
this.emitState()
}
@@ -324,12 +320,15 @@ export default class StreamWindow extends EventEmitter {
onState(state) {
this.send('state', state)
for (const stream of state.streams) {
const { link } = stream
this.viewsByURL.get(link)?.send?.({
type: 'OPTIONS',
options: getDisplayOptions(stream),
})
for (const view of this.views.values()) {
const { url } = view.state.context.content
const stream = state.streams.byURL.get(url)
if (stream) {
view.send({
type: 'OPTIONS',
options: getDisplayOptions(stream),
})
}
}
}

View File

@@ -67,7 +67,10 @@ export async function* combineDataSources(dataSources) {
dataByURL.set(data.link, { ...existing, ...data })
}
}
yield [...dataByURL.values()]
const streams = [...dataByURL.values()]
// Retain the index to speed up local lookups
streams.byURL = dataByURL
yield streams
}
}