mirror of
https://github.com/leptos-rs/leptos
synced 2024-11-10 06:44:17 +00:00
docs: runtime error if setting the same event listener 2x rather than silent failure (#2383)
Delegated event listeners do not support adding more than one event listener of the same type. This can cause confusion if two listeners are added, as one is silently dropped.
This commit is contained in:
parent
943a992570
commit
2b4f5e0f58
1 changed files with 6 additions and 0 deletions
|
@ -70,6 +70,12 @@ pub fn add_event_listener<E>(
|
|||
|
||||
let cb = Closure::wrap(cb as Box<dyn FnMut(E)>).into_js_value();
|
||||
let key = intern(&key);
|
||||
debug_assert_eq!(
|
||||
Ok(false),
|
||||
js_sys::Reflect::has(target, &JsValue::from_str(&key)),
|
||||
"Error while adding {key} event listener, a listener of type {key} \
|
||||
already present."
|
||||
);
|
||||
_ = js_sys::Reflect::set(target, &JsValue::from_str(&key), &cb);
|
||||
add_delegated_event_listener(&key, event_name, options);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue