BumpyClock/agent-templates / skills/programming
programming
UnverifiedImplement, debug, refactor, or review code with scoped changes and evidence.
references/gpui/references/global.md
View on GitHub# Global state
Use `Global` for state whose ownership belongs to the application.
Use entities for state with an independent owner or lifetime.
Frequency of change alone does not determine the choice.
Initialize required globals before access through `global::<T>()`.
Use optional access when absence is a valid state.
## Mutation and observation
Use GPUI global mutation APIs for GPUI-owned state.
Check `observe_global` and the mutation API's notification behavior in the resolved version.
Do not assume all global changes are silent.
Interior mutation through an `Arc`, lock, or atomic can bypass GPUI notification paths.
Use those types when cross-thread ownership requires them, not as a default for mutable globals.
Notify dependent views through the application's established path.
## Application setting example
This fragment uses the GPUI 0.2.2 `Global`, `set_global`, and `global_mut` APIs.
It is not a standalone compiled example.
```rust
struct Preferences {
compact: bool,
}
impl Global for Preferences {}
cx.set_global(Preferences { compact: false });
cx.global_mut::<Preferences>().compact = true;
```
A dependent entity can retain an observation subscription:
```rust
let subscription = cx.observe_global::<Preferences>(|_, cx| {
cx.notify();
});
```
The returned handle belongs in that entity's state.
In this API, `global_mut` marks the global for observer notification.
Mutation of a nested atomic through an immutable global reference does not use that same path.
For a theme or preference cache, preserve the existing notification contract rather than adding a second event bus.
Source: [App global APIs](https://docs.rs/gpui/latest/gpui/struct.App.html).
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the work | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |