refactor: make callback registration chainable

This commit is contained in:
drendog 2025-12-12 02:36:02 +01:00
parent 2095c231d0
commit 2c484ef392
Signed by: dwenya
GPG key ID: 8DD77074645332D0

View file

@ -20,22 +20,24 @@ impl<'a> Selection<'a> {
Self { shell, selector } Self { shell, selector }
} }
pub fn on_callback<F, R>(&self, callback_name: &str, handler: F) pub fn on_callback<F, R>(&mut self, callback_name: &str, handler: F) -> &mut Self
where where
F: Fn(crate::ShellControl) -> R + Clone + 'static, F: Fn(crate::ShellControl) -> R + Clone + 'static,
R: crate::IntoValue, R: crate::IntoValue,
{ {
self.shell self.shell
.on_internal(&self.selector, callback_name, handler); .on_internal(&self.selector, callback_name, handler);
self
} }
pub fn on_callback_with_args<F, R>(&self, callback_name: &str, handler: F) pub fn on_callback_with_args<F, R>(&mut self, callback_name: &str, handler: F) -> &mut Self
where where
F: Fn(&[Value], crate::ShellControl) -> R + Clone + 'static, F: Fn(&[Value], crate::ShellControl) -> R + Clone + 'static,
R: crate::IntoValue, R: crate::IntoValue,
{ {
self.shell self.shell
.on_with_args_internal(&self.selector, callback_name, handler); .on_with_args_internal(&self.selector, callback_name, handler);
self
} }
pub fn with_component<F>(&self, mut f: F) pub fn with_component<F>(&self, mut f: F)