@@ -39,7 +39,7 @@ where
3939 /// # Example
4040 ///
4141 /// ```no_run
42− /// use dodrio::{builder::*, bumpalo::Bump, on};
42+ /// use dodrio::{builder::*, bumpalo::Bump};
4343 ///
4444 /// let b = Bump::new();
4545 ///
@@ -856,3 +856,29 @@ pub fn text<'a>(contents: &'a str) -> Node<'a> {
856856pub fn attr<'a>(name: &'a str, value: &'a str) -> Attribute<'a> {
857857 Attribute { name, value }
858858}
859+
860+/// Create an event listener.
861+///
862+/// `event` is the type of event to listen for, e.g. `"click"`. The `callback`
863+/// is the function that will be invoked when the event occurs.
864+///
865+/// # Example
866+///
867+/// ```no_run
868+/// use dodrio::{builder::*, bumpalo::Bump};
869+///
870+/// let b = Bump::new();
871+///
872+/// let listener = on(&b, "click", |root, vdom, event| {
873+/// // do something when a click happens...
874+/// });
875+/// ```
876+pub fn on<'a, F>(bump: &'a Bump, event: &'a str, callback: F) -> Listener<'a>
877+where
878+ F: Fn(&mut dyn RootRender, VdomWeak, web_sys::Event) + 'static,
879+{
880+ Listener {
881+ event,
882+ callback: bump.alloc(callback),
883+ }
884+}