all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [PATCH yew-widget-toolkit v2 1/6] state: event: add helpers for custom DOM events
Date: Fri, 27 Nov 2026 18:09:22 +0100	[thread overview]
Message-ID: <20261127170941.4183880-2-d.csapak@proxmox.com> (raw)
In-Reply-To: <20261127170941.4183880-1-d.csapak@proxmox.com>

Creating and dispatching custom events is currently open coded, e.g. for
the `pwt-theme-changed` event. Provide small wrappers so that further
users do not have to repeat the window/document lookup and the JS error
conversion.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 src/state/event.rs | 24 ++++++++++++++++++++++++
 src/state/mod.rs   |  3 +++
 2 files changed, 27 insertions(+)
 create mode 100644 src/state/event.rs

diff --git a/src/state/event.rs b/src/state/event.rs
new file mode 100644
index 0000000..8566071
--- /dev/null
+++ b/src/state/event.rs
@@ -0,0 +1,24 @@
+//! Helpers to create and dispatch custom DOM events.
+
+use anyhow::{Error, format_err};
+use web_sys::Event;
+
+/// Create a custom [Event] with the given name.
+pub fn create_custom_event(name: &str) -> Result<Event, Error> {
+    Event::new(name).map_err(crate::convert_js_error)
+}
+
+/// Dispatch a custom event with the given name on the document.
+///
+/// The event is only delivered to listeners in the current document, so listeners in other
+/// browser tabs or windows are not notified.
+pub fn dispatch_custom_event(name: &str) -> Result<(), Error> {
+    let document = web_sys::window()
+        .and_then(|window| window.document())
+        .ok_or_else(|| format_err!("no document available"))?;
+
+    document
+        .dispatch_event(&create_custom_event(name)?)
+        .map(|_| ())
+        .map_err(crate::convert_js_error)
+}
diff --git a/src/state/mod.rs b/src/state/mod.rs
index d98d4db..d473ad2 100644
--- a/src/state/mod.rs
+++ b/src/state/mod.rs
@@ -7,6 +7,9 @@ use serde::{Serialize, de::DeserializeOwned};
 mod data_store;
 pub use data_store::{DataNode, DataNodeDerefGuard, DataStore};
 
+mod event;
+pub use event::{create_custom_event, dispatch_custom_event};
+
 mod loader;
 pub use loader::{Loader, LoaderState};
 
-- 
2.47.3





  reply	other threads:[~2026-11-27 17:09 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 17:09 [PATCH datacenter-manager/yew-widget-toolkit v2 0/6] ui: make the default dashboard configurable and add "My Settings" dialog Dominik Csapak
2026-11-27 17:09 ` Dominik Csapak [this message]
2026-11-27 17:09 ` [PATCH yew-widget-toolkit v2 2/6] state: persistent state: allow listening for updates Dominik Csapak
2026-11-27 17:09 ` [PATCH datacenter-manager v2 3/6] ui: add 'My Settings' dialog with xterm.js and noVNC settings Dominik Csapak
2026-11-27 17:09 ` [PATCH datacenter-manager v2 4/6] ui: view configuration: fix dismissing of remove confirmation dialog Dominik Csapak
2026-11-27 17:09 ` [PATCH datacenter-manager v2 5/6] ui: view selector: use a placeholder that can't conflict with a view Dominik Csapak
2026-11-27 17:09 ` [PATCH datacenter-manager v2 6/6] ui: make the default dashboard page configurable Dominik Csapak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261127170941.4183880-2-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pdm-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal