Skip to repository content155 lines · 4.1 KB · rust
tenant.openagents/omega
No repository description is available.
OpenAgents Git authority 2026-07-28T04:36:17.650Z Public web read
NIP-34 coordinate
30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omegaMaintainersHidden in public view
References2 branches · 1 tag
Read-only clone
git clone https://openagents.com/git/tenant.openagents/omega.gitBrowse files
lib.rs
1#![allow(unused, dead_code)]
2
3use gpui::*;
4
5// ============================================================
6// Helper types for tests
7// ============================================================
8
9struct Editor;
10
11impl Editor {
12 fn set_text(&mut self, _text: &str) {}
13 fn text(&self) -> String {
14 String::new()
15 }
16}
17
18struct Counter {
19 count: u32,
20 editor: Entity<Editor>,
21}
22
23struct CounterOnce {
24 editor: Entity<Editor>,
25 weak_editor: WeakEntity<Editor>,
26}
27
28// ============================================================
29// entity_update_in_render — SHOULD WARN
30// ============================================================
31
32// Entity::update with unit-returning closure in Render::render
33impl Render for Counter {
34 fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
35 self.editor.update(cx, |editor, _cx| {
36 editor.set_text("hello");
37 });
38 ()
39 }
40}
41
42// Entity::update with unit-returning closure in RenderOnce::render
43impl RenderOnce for CounterOnce {
44 fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
45 self.editor.update(cx, |editor, _cx| {
46 editor.set_text("hello");
47 });
48 ()
49 }
50}
51
52// WeakEntity::update with unit-returning closure in RenderOnce::render
53struct WeakUpdater {
54 weak_editor: WeakEntity<Editor>,
55}
56
57impl RenderOnce for WeakUpdater {
58 fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
59 let _ = self.weak_editor.update(cx, |editor, _cx| {
60 editor.set_text("world");
61 });
62 ()
63 }
64}
65
66// ============================================================
67// entity_update_in_render — SHOULD NOT WARN
68// ============================================================
69
70// Entity::update with value-returning closure (reading, not mutating)
71struct ReaderView {
72 editor: Entity<Editor>,
73}
74
75impl RenderOnce for ReaderView {
76 fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
77 let _text = self.editor.update(cx, |editor, _cx| editor.text());
78 ()
79 }
80}
81
82// Entity::update outside render entirely
83fn update_outside_render(editor: &Entity<Editor>, cx: &mut App) {
84 editor.update(cx, |editor, _cx| {
85 editor.set_text("fine here");
86 });
87}
88
89// Entity::read in render (not update)
90struct ReadOnlyView {
91 editor: Entity<Editor>,
92}
93
94impl RenderOnce for ReadOnlyView {
95 fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
96 let _editor = self.editor.read(cx);
97 ()
98 }
99}
100
101// Entity::update inside a closure in render (simulating an event handler
102// that executes later, not during render itself)
103struct ClosureView {
104 editor: Entity<Editor>,
105}
106
107impl RenderOnce for ClosureView {
108 fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
109 let editor = self.editor;
110 let _handler = move |cx: &mut App| {
111 editor.update(cx, |editor, _cx| {
112 editor.set_text("inside closure");
113 });
114 };
115 ()
116 }
117}
118
119// ============================================================
120// notify_in_render — SHOULD WARN
121// ============================================================
122
123struct NotifyView {
124 count: u32,
125}
126
127impl Render for NotifyView {
128 fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
129 self.count += 1;
130 cx.notify();
131 ()
132 }
133}
134
135// ============================================================
136// notify_in_render — SHOULD NOT WARN
137// ============================================================
138
139// notify outside render
140fn notify_outside_render<T>(cx: &mut Context<'_, T>) {
141 cx.notify();
142}
143
144// notify inside a closure in render (event handler — runs later)
145struct NotifyClosureView;
146
147impl Render for NotifyClosureView {
148 fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
149 let _handler = |cx: &mut Context<'_, Self>| {
150 cx.notify();
151 };
152 ()
153 }
154}
155