From 8eb735cb21c408ecee5169feb4a4aaf478135c0c Mon Sep 17 00:00:00 2001 From: Lucas Pickering Date: Wed, 1 Jan 2025 10:10:14 -0500 Subject: [PATCH] Rename EmitterToken -> EmitterHandle I think the name is a bit more obvious/consistent. --- crates/tui/src/view/common/modal.rs | 6 +++--- crates/tui/src/view/common/text_box.rs | 2 +- .../src/view/component/recipe_pane/authentication.rs | 6 +++--- crates/tui/src/view/component/recipe_pane/body.rs | 2 +- crates/tui/src/view/component/recipe_pane/table.rs | 6 +++--- crates/tui/src/view/event.rs | 10 +++++----- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/crates/tui/src/view/common/modal.rs b/crates/tui/src/view/common/modal.rs index 23454426..64dd9599 100644 --- a/crates/tui/src/view/common/modal.rs +++ b/crates/tui/src/view/common/modal.rs @@ -3,7 +3,7 @@ use crate::{ view::{ context::UpdateContext, draw::{Draw, DrawMetadata}, - event::{Child, Emitter, EmitterToken, Event, EventHandler, Update}, + event::{Child, Emitter, EmitterHandle, Event, EventHandler, Update}, util::centered_rect, Component, ViewContext, }, @@ -209,7 +209,7 @@ pub struct ModalHandle { /// plumbing but would not actually accomplish anything. Once a modal is /// closed, it won't be emitting anymore so there's no harm in hanging onto /// its ID. - emitter: Option>, + emitter: Option>, } impl ModalHandle { @@ -222,7 +222,7 @@ impl ModalHandle { where T: 'static + Modal, { - self.emitter = Some(modal.detach()); + self.emitter = Some(modal.handle()); ViewContext::open_modal(modal); } diff --git a/crates/tui/src/view/common/text_box.rs b/crates/tui/src/view/common/text_box.rs index ed87081d..243440d3 100644 --- a/crates/tui/src/view/common/text_box.rs +++ b/crates/tui/src/view/common/text_box.rs @@ -170,7 +170,7 @@ impl TextBox { if let Some(debounce) = &self.on_change_debounce { if self.is_valid() { // Defer the change event until after the debounce period - let emitter = self.detach(); + let emitter = self.handle(); debounce.start(move || emitter.emit(TextBoxEvent::Change)); } else { debounce.cancel(); diff --git a/crates/tui/src/view/component/recipe_pane/authentication.rs b/crates/tui/src/view/component/recipe_pane/authentication.rs index a78a1039..01d0b591 100644 --- a/crates/tui/src/view/component/recipe_pane/authentication.rs +++ b/crates/tui/src/view/component/recipe_pane/authentication.rs @@ -11,7 +11,7 @@ use crate::{ context::UpdateContext, draw::{Draw, DrawMetadata, Generate}, event::{ - Child, Emitter, EmitterId, EmitterToken, Event, EventHandler, + Child, Emitter, EmitterHandle, EmitterId, Event, EventHandler, Update, }, state::fixed_select::FixedSelectState, @@ -101,7 +101,7 @@ impl EventHandler for AuthenticationDisplay { fn update(&mut self, _: &mut UpdateContext, event: Event) -> Update { let action = event.action(); if let Some(Action::Edit) = action { - self.state.open_edit_modal(self.detach()); + self.state.open_edit_modal(self.handle()); } else if let Some(Action::Reset) = action { self.state.reset_override(); } else if let Some(SaveAuthenticationOverride(value)) = @@ -218,7 +218,7 @@ impl State { /// Open a modal to let the user edit temporary override values fn open_edit_modal( &self, - emitter: EmitterToken, + emitter: EmitterHandle, ) { let (label, value) = match &self { Self::Basic { diff --git a/crates/tui/src/view/component/recipe_pane/body.rs b/crates/tui/src/view/component/recipe_pane/body.rs index e558bd38..0cd8ca0c 100644 --- a/crates/tui/src/view/component/recipe_pane/body.rs +++ b/crates/tui/src/view/component/recipe_pane/body.rs @@ -166,7 +166,7 @@ impl RawBody { return; }; - let emitter = self.detach(); + let emitter = self.handle(); ViewContext::send_message(Message::FileEdit { path, on_complete: Box::new(move |path| { diff --git a/crates/tui/src/view/component/recipe_pane/table.rs b/crates/tui/src/view/component/recipe_pane/table.rs index 2aaaf734..8b56a181 100644 --- a/crates/tui/src/view/component/recipe_pane/table.rs +++ b/crates/tui/src/view/component/recipe_pane/table.rs @@ -14,7 +14,7 @@ use crate::{ context::UpdateContext, draw::{Draw, DrawMetadata, Generate}, event::{ - Child, Emitter, EmitterId, EmitterToken, Event, EventHandler, + Child, Emitter, EmitterHandle, EmitterId, Event, EventHandler, Update, }, state::select::{SelectState, SelectStateEvent, SelectStateEventType}, @@ -118,7 +118,7 @@ where // Consume the event even if we have no rows, for // consistency if let Some(selected_row) = self.select.data().selected() { - selected_row.open_edit_modal(self.detach()); + selected_row.open_edit_modal(self.handle()); } } Action::Reset => { @@ -266,7 +266,7 @@ impl> RowState { } /// Open a modal to create or edit the value's temporary override - fn open_edit_modal(&self, emitter: EmitterToken) { + fn open_edit_modal(&self, emitter: EmitterHandle) { let index = self.index; ViewContext::open_modal(TextBoxModal::new( format!("Edit value for {}", self.key), diff --git a/crates/tui/src/view/event.rs b/crates/tui/src/view/event.rs index 35dfc15a..2c0cf4da 100644 --- a/crates/tui/src/view/event.rs +++ b/crates/tui/src/view/event.rs @@ -301,8 +301,8 @@ pub trait Emitter { /// Get a lightweight version of this emitter, with the same type and ID but /// datched from this lifetime. Useful for both emitting and consuming /// emissions from across task boundaries, modals, etc. - fn detach(&self) -> EmitterToken { - EmitterToken { + fn handle(&self) -> EmitterHandle { + EmitterHandle { id: self.id(), phantom: PhantomData, } @@ -364,7 +364,7 @@ impl Default for EmitterId { /// A lightweight copy of an emitter that can be passed between threads or /// callbacks. This has the same emitting capability as the source emitter /// because it contains its ID and is bound to its emitted event type. Generate -/// via [Emitter::detach]. +/// via [Emitter::handle]. /// /// It would be good to impl `!Send` for this type because it shouldn't be /// passed between threads, but there is one use case where it needs to be Send @@ -372,12 +372,12 @@ impl Default for EmitterId { /// threads. !Send is more correct because if you try to emit from another /// thread it'll panic, because the event queue isn't available there. #[derive(Debug)] -pub struct EmitterToken { +pub struct EmitterHandle { id: EmitterId, phantom: PhantomData, } -impl Emitter for EmitterToken { +impl Emitter for EmitterHandle { type Emitted = T; fn id(&self) -> EmitterId {