Skip to repository content51 lines · 1.2 KB · rust
tenant.openagents/omega
No repository description is available.
OpenAgents Git authority 2026-07-28T04:48:48.487Z 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
ownership_post.rs
1#![cfg_attr(target_family = "wasm", no_main)]
2
3use gpui::{App, Context, Entity, EventEmitter, prelude::*};
4use gpui_platform::application;
5
6struct Counter {
7 count: usize,
8}
9
10struct Change {
11 increment: usize,
12}
13
14impl EventEmitter<Change> for Counter {}
15
16fn run_example() {
17 application().run(|cx: &mut App| {
18 let counter: Entity<Counter> = cx.new(|_cx| Counter { count: 0 });
19 let subscriber = cx.new(|cx: &mut Context<Counter>| {
20 cx.subscribe(&counter, |subscriber, _emitter, event, _cx| {
21 subscriber.count += event.increment * 2;
22 })
23 .detach();
24
25 Counter {
26 count: counter.read(cx).count * 2,
27 }
28 });
29
30 counter.update(cx, |counter, cx| {
31 counter.count += 2;
32 cx.notify();
33 cx.emit(Change { increment: 2 });
34 });
35
36 assert_eq!(subscriber.read(cx).count, 4);
37 });
38}
39
40#[cfg(not(target_family = "wasm"))]
41fn main() {
42 run_example();
43}
44
45#[cfg(target_family = "wasm")]
46#[wasm_bindgen::prelude::wasm_bindgen(start)]
47pub fn start() {
48 gpui_platform::web_init();
49 run_example();
50}
51