Use read() over read_with() to improve readability in simple cases (#31263)

Release Notes:

- N/A
This commit is contained in:
Joseph T. Lyons 2025-05-23 08:08:49 -04:00 committed by GitHub
parent e88cad29e5
commit 6206150e27
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 11 additions and 18 deletions

View file

@ -153,13 +153,10 @@ impl Render for ProfileSelector {
.map(|profile| profile.name.clone()) .map(|profile| profile.name.clone())
.unwrap_or_else(|| "Unknown".into()); .unwrap_or_else(|| "Unknown".into());
let configured_model = self let configured_model = self.thread.read(cx).configured_model().or_else(|| {
.thread let model_registry = LanguageModelRegistry::read_global(cx);
.read_with(cx, |thread, _cx| thread.configured_model()) model_registry.default_model()
.or_else(|| { });
let model_registry = LanguageModelRegistry::read_global(cx);
model_registry.default_model()
});
let supports_tools = let supports_tools =
configured_model.map_or(false, |default| default.model.supports_tools()); configured_model.map_or(false, |default| default.model.supports_tools());

View file

@ -109,9 +109,7 @@ impl ProjectSharedNotification {
} }
fn dismiss(&mut self, cx: &mut Context<Self>) { fn dismiss(&mut self, cx: &mut Context<Self>) {
if let Some(active_room) = if let Some(active_room) = ActiveCall::global(cx).read(cx).room().cloned() {
ActiveCall::global(cx).read_with(cx, |call, _| call.room().cloned())
{
active_room.update(cx, |_, cx| { active_room.update(cx, |_, cx| {
cx.emit(room::Event::RemoteProjectInvitationDiscarded { cx.emit(room::Event::RemoteProjectInvitationDiscarded {
project_id: self.project_id, project_id: self.project_id,

View file

@ -349,9 +349,7 @@ impl DebugPanel {
window: &mut Window, window: &mut Window,
cx: &mut Context<Self>, cx: &mut Context<Self>,
) { ) {
while let Some(parent_session) = while let Some(parent_session) = curr_session.read(cx).parent_session().cloned() {
curr_session.read_with(cx, |session, _| session.parent_session().cloned())
{
curr_session = parent_session; curr_session = parent_session;
} }

View file

@ -1121,10 +1121,10 @@ impl MultiBuffer {
pub fn last_transaction_id(&self, cx: &App) -> Option<TransactionId> { pub fn last_transaction_id(&self, cx: &App) -> Option<TransactionId> {
if let Some(buffer) = self.as_singleton() { if let Some(buffer) = self.as_singleton() {
return buffer.read_with(cx, |b, _| { return buffer
b.peek_undo_stack() .read(cx)
.map(|history_entry| history_entry.transaction_id()) .peek_undo_stack()
}); .map(|history_entry| history_entry.transaction_id());
} else { } else {
let last_transaction = self.history.undo_stack.last()?; let last_transaction = self.history.undo_stack.last()?;
return Some(last_transaction.id); return Some(last_transaction.id);

View file

@ -536,7 +536,7 @@ impl HeadlessProject {
}); });
} }
let buffer_id = buffer.read_with(cx, |b, _| b.remote_id()); let buffer_id = buffer.read(cx).remote_id();
buffer_store.update(cx, |buffer_store, cx| { buffer_store.update(cx, |buffer_store, cx| {
buffer_store buffer_store