diff --git a/rust/perspective-viewer/src/rust/model/intersection_observer.rs b/rust/perspective-viewer/src/rust/model/intersection_observer.rs index f9dec85468..66ac8ef391 100644 --- a/rust/perspective-viewer/src/rust/model/intersection_observer.rs +++ b/rust/perspective-viewer/src/rust/model/intersection_observer.rs @@ -38,8 +38,9 @@ impl IntersectionObserverHandle { ) -> Self { clone!(session, renderer, presentation); let _callback = Closure::new(move |xs: js_sys::Array| { + // https://stackoverflow.com/questions/53862160/intersectionobserver-multiple-entries let intersect = xs - .get(0) + .pop() .unchecked_into::() .is_intersecting(); @@ -49,6 +50,7 @@ impl IntersectionObserverHandle { session, renderer, }; + ApiFuture::spawn(state.set_pause(intersect)); }); diff --git a/rust/perspective-viewer/src/rust/renderer/registry.rs b/rust/perspective-viewer/src/rust/renderer/registry.rs index 27df0048a5..a581c92e52 100644 --- a/rust/perspective-viewer/src/rust/renderer/registry.rs +++ b/rust/perspective-viewer/src/rust/renderer/registry.rs @@ -102,7 +102,14 @@ pub impl LocalKey>>> { .unwrap_or_else(|| "Custom".to_owned()), priority: plugin_inst.priority().unwrap_or_default(), }; + let mut plugins = plugin.borrow_mut(); + if let Some(first) = plugins.first() + && first.tag_name.as_str() == "perspective-viewer-plugin" + { + plugins.clear(); + } + plugins.push(record); plugins.sort_by(|a, b| Ord::cmp(&b.priority, &a.priority)); }); @@ -121,7 +128,7 @@ fn register_default() { name: "Debug".to_owned(), category: "Custom".to_owned(), tag_name: "perspective-viewer-plugin".to_owned(), - priority: 0, + priority: -1, }) } }) diff --git a/rust/perspective-viewer/test/html/superstore_lazy_viewer.html b/rust/perspective-viewer/test/html/superstore_lazy_viewer.html new file mode 100644 index 0000000000..fc2aa2b084 --- /dev/null +++ b/rust/perspective-viewer/test/html/superstore_lazy_viewer.html @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/rust/perspective-viewer/test/js/viewnotfound.spec.js b/rust/perspective-viewer/test/js/viewnotfound.spec.js index 6a74c749ca..544f5ee004 100644 --- a/rust/perspective-viewer/test/js/viewnotfound.spec.js +++ b/rust/perspective-viewer/test/js/viewnotfound.spec.js @@ -13,7 +13,10 @@ import { test, expect } from "@perspective-dev/test"; test("View conflation is silenced", async ({ page }) => { - await page.goto("/rust/perspective-viewer/test/html/superstore.html"); + await page.goto( + "/rust/perspective-viewer/test/html/superstore_lazy_viewer.html", + ); + await page.evaluate(async () => { while (!window["__TEST_PERSPECTIVE_READY__"]) { await new Promise((x) => setTimeout(x, 10)); @@ -53,30 +56,31 @@ test("View conflation is silenced", async ({ page }) => { customElements.define("pause-plugin", PausePlugin); const Viewer = customElements.get("perspective-viewer"); - await Viewer.registerPlugin("pause-plugin"); + Viewer.registerPlugin("pause-plugin"); // use a new viewer because only new viewers get loaded with the registered plugin const viewer = document.createElement("perspective-viewer"); document.body.append(viewer); - const table = worker.table("a,b,c\n1,2,3", { name: "A" }); + worker.table("a,b,c\n1,2,3", { name: "A" }); - await viewer.load(table); - await viewer.restore({ plugin: "pause-plugin" }); + await viewer.load(worker); + await viewer.restore({ table: "A", plugin: "pause-plugin" }); is_paused = true; // Change in 4.1.0 - empty restore now does not render - const restore_task = viewer.restore({ plugin: "pause-plugin" }); + const restore_task = viewer.restore({ + plugin: "pause-plugin", + }); + while (!resolve) { await new Promise((x) => setTimeout(x, 0)); } - const load_task = viewer.load(table); await new Promise((x) => setTimeout(x, 0)); resolve(); resolve = undefined; is_paused = false; await restore_task; - await load_task; }); expect(vnf).toBeFalsy(); diff --git a/tools/test/load-viewer.js b/tools/test/load-viewer.js new file mode 100644 index 0000000000..f23b2a2619 --- /dev/null +++ b/tools/test/load-viewer.js @@ -0,0 +1,22 @@ +// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ +// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃ +// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃ +// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃ +// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃ +// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫ +// ┃ Copyright (c) 2017, the Perspective Authors. ┃ +// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃ +// ┃ This file is part of the Perspective library, distributed under the terms ┃ +// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃ +// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ + +import "/node_modules/@perspective-dev/viewer/dist/cdn/perspective-viewer.js"; +import perspective from "/node_modules/@perspective-dev/client/dist/cdn/perspective.js"; + +async function load() { + const worker = await perspective.worker(); + window.__TEST_WORKER__ = worker; +} + +await load(); +window.__TEST_PERSPECTIVE_READY__ = true;