Skip to repository content

tenant.openagents/omega

No repository description is available.

OpenAgents Git authority 2026-07-28T03:54:38.116Z Public web read
NIP-34 coordinate30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omega
MaintainersHidden in public view
References2 branches · 1 tag
Read-only clonegit clone https://openagents.com/git/tenant.openagents/omega.git
Browse files

entity_update_in_render.rs

117 lines · 2.8 KB · rust
1// Tests for the `entity_update_in_render` lint.
2
3#![allow(unused)]
4
5extern crate gpui;
6
7use gpui::*;
8
9struct Counter {
10    value: i32,
11}
12
13// ============================================================
14// SHOULD WARN — .update() returning () inside Render::render
15// ============================================================
16
17struct MutatingView {
18    counter: Entity<Counter>,
19}
20
21impl Render for MutatingView {
22    fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
23        self.counter.update(cx, |counter, _cx| {
24            counter.value += 1;
25        });
26        ()
27    }
28}
29
30// WeakEntity::update returning Result<(), _> inside Render::render
31struct WeakMutatingView {
32    counter: WeakEntity<Counter>,
33}
34
35impl Render for WeakMutatingView {
36    fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
37        let _ = self.counter.update(cx, |counter, _cx| {
38            counter.value += 1;
39        });
40        ()
41    }
42}
43
44// Entity::update returning () inside RenderOnce::render
45struct OnceMutatingView {
46    counter: Entity<Counter>,
47}
48
49impl RenderOnce for OnceMutatingView {
50    fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
51        self.counter.update(cx, |counter, _cx| {
52            counter.value += 1;
53        });
54        ()
55    }
56}
57
58// ============================================================
59// SHOULD NOT WARN
60// ============================================================
61
62// .update() returning a value (reading, not mutating)
63struct ReadingView {
64    counter: Entity<Counter>,
65}
66
67impl Render for ReadingView {
68    fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
69        let _val: i32 = self.counter.update(cx, |counter, _cx| counter.value);
70        ()
71    }
72}
73
74// .update() inside a closure (e.g. event handler), not directly in render
75struct ClosureView {
76    counter: Entity<Counter>,
77}
78
79impl Render for ClosureView {
80    fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
81        let counter = &self.counter;
82        let _handler = |cx: &mut App| {
83            counter.update(cx, |counter, _cx| {
84                counter.value += 1;
85            });
86        };
87        ()
88    }
89}
90
91// .update() outside of render entirely
92fn update_outside_render(entity: &Entity<Counter>, cx: &mut App) {
93    entity.update(cx, |counter, _cx| {
94        counter.value += 1;
95    });
96}
97
98// .update() on a non-gpui type (unrelated method named "update")
99struct FakeEntity;
100
101impl FakeEntity {
102    fn update(&self) {}
103}
104
105struct FakeView {
106    thing: FakeEntity,
107}
108
109impl Render for FakeView {
110    fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
111        self.thing.update();
112        ()
113    }
114}
115
116fn main() {}
117
Served at tenant.openagents/omega Member data and write actions are omitted.