mirror of
https://github.com/streamwall/streamwall.git
synced 2026-01-31 09:22:49 -05:00
Prefer to reuse loaded view if it exists
This commit is contained in:
@@ -123,15 +123,27 @@ export default class StreamWindow extends EventEmitter {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: prefer fully loaded views
|
const unusedViewsArray = views.filter((s) => unusedViews.has(s))
|
||||||
let space = views.find(
|
const matchingURLViews = unusedViewsArray.filter(
|
||||||
(s) => unusedViews.has(s) && s.state.context.url === url,
|
(s) => s.state.context.url === url,
|
||||||
|
)
|
||||||
|
|
||||||
|
// First try to find a loaded view of the same URL...
|
||||||
|
let space = matchingURLViews.find((s) =>
|
||||||
|
s.state.matches('displaying.running'),
|
||||||
)
|
)
|
||||||
if (!space) {
|
if (!space) {
|
||||||
space = views.find(
|
// Then try view with the same URL that is still loading...
|
||||||
(s) => unusedViews.has(s) && !s.state.matches('displaying'),
|
space = matchingURLViews[0]
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
if (!space) {
|
||||||
|
// If none could be found, launch a new view.
|
||||||
|
space = unusedViewsArray[0]
|
||||||
|
}
|
||||||
|
if (!space) {
|
||||||
|
throw new Error('could not find a usable view')
|
||||||
|
}
|
||||||
|
|
||||||
const pos = {
|
const pos = {
|
||||||
x: SPACE_WIDTH * x,
|
x: SPACE_WIDTH * x,
|
||||||
y: SPACE_HEIGHT * y,
|
y: SPACE_HEIGHT * y,
|
||||||
|
|||||||
Reference in New Issue
Block a user