From: Dominik Csapak <d.csapak@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [PATCH yew-widget-toolkit 1/3] state: event: add helpers for custom DOM events
Date: Thu, 20 Aug 2026 10:17:37 +0200 [thread overview]
Message-ID: <20260820081746.989972-2-d.csapak@proxmox.com> (raw)
In-Reply-To: <20260820081746.989972-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 86d6b7f..6f99c7e 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
next prev parent reply other threads:[~2026-08-20 8:17 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-20 8:17 [PATCH datacenter-manager/yew-widget-toolkit 0/3] ui: make the default dashboard configurable Dominik Csapak
2026-08-20 8:17 ` Dominik Csapak [this message]
2026-08-20 8:17 ` [PATCH yew-widget-toolkit 2/3] state: persistent state: allow listening for updates Dominik Csapak
2026-08-20 8:17 ` [PATCH datacenter-manager 3/3] 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=20260820081746.989972-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.