gpui: Improve Global
ergonomics (#11923)
This PR adds some ergonomic improvements when working with GPUI `Global`s. Two new traits have been added—`ReadGlobal` and `UpdateGlobal`—that provide associated functions on any type that implements `Global` for accessing and updating the global without needing to call the methods on the `cx` directly (which generally involves qualifying the type). I looked into adding `ObserveGlobal` as well, but this seems a bit trickier to implement as the signatures of `cx.observe_global` vary slightly between the different contexts. Release Notes: - N/A
This commit is contained in:
parent
1b261608c6
commit
c1e291bc96
8 changed files with 81 additions and 33 deletions
|
@ -418,7 +418,7 @@ fn merge<T: Copy>(target: &mut T, value: Option<T>) {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use gpui::{AppContext, BorrowAppContext};
|
||||
use gpui::{AppContext, UpdateGlobal};
|
||||
use settings::SettingsStore;
|
||||
|
||||
use super::*;
|
||||
|
@ -440,7 +440,7 @@ mod tests {
|
|||
);
|
||||
|
||||
// Ensure backward-compatibility.
|
||||
cx.update_global::<SettingsStore, _>(|store, cx| {
|
||||
SettingsStore::update_global(cx, |store, cx| {
|
||||
store
|
||||
.set_user_settings(
|
||||
r#"{
|
||||
|
@ -460,7 +460,7 @@ mod tests {
|
|||
low_speed_timeout_in_seconds: None,
|
||||
}
|
||||
);
|
||||
cx.update_global::<SettingsStore, _>(|store, cx| {
|
||||
SettingsStore::update_global(cx, |store, cx| {
|
||||
store
|
||||
.set_user_settings(
|
||||
r#"{
|
||||
|
@ -482,7 +482,7 @@ mod tests {
|
|||
);
|
||||
|
||||
// The new version supports setting a custom model when using zed.dev.
|
||||
cx.update_global::<SettingsStore, _>(|store, cx| {
|
||||
SettingsStore::update_global(cx, |store, cx| {
|
||||
store
|
||||
.set_user_settings(
|
||||
r#"{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue