You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .claude/rules/event-patterns.md
+21Lines changed: 21 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,26 @@
1
1
# Event Patterns
2
2
3
+
## When to Use `-ing` vs `-ed` Events
4
+
5
+
Terminal.Gui exposes paired events — `Accepting`/`Accepted`, `Activating`/`Activated`, `ValueChanging`/`ValueChanged`, etc.
6
+
7
+
**Rule:** Use `-ed` (past-tense) for side-effects. Use `-ing` (present-progressive) only when you need to inspect or cancel the in-flight operation.
8
+
9
+
```csharp
10
+
// ✅ Correct — fire-and-forget side-effect
11
+
button.Accepted+= (_, _) =>DoTheThing ();
12
+
13
+
// ✅ Correct — actually cancels
14
+
button.Accepting+= (_, e) => { if (!CanProceed ()) e.Handled=true; };
15
+
16
+
// ❌ Wrong — handler ignores EventArgs; use Accepted instead
17
+
button.Accepting+= (_, _) =>DoTheThing ();
18
+
```
19
+
20
+
If the handler body doesn't reference `e` at all (or ignores `e.Handled`, `e.Cancel`, and the candidate value), it belongs on the `-ed` event.
21
+
22
+
The `-ing` event runs synchronously in the middle of the dispatch path; subscribing when you don't need to cancel adds unnecessary overhead and misleads readers.
Terminal.Gui exposes paired events on many surfaces — `Accepting`/`Accepted`, `Activating`/`Activated`, `ValueChanging`/`ValueChanged`, etc. Use this rule to choose:
48
+
49
+
> **Use `-ed` (past-tense) events for side-effects. Use `-ing` (present-progressive) events only when you actually need to inspect or cancel the in-flight operation.**
50
+
51
+
If your handler doesn't read or set anything on the `EventArgs` (no `e.Handled`, no `e.Cancel`, no inspection of the candidate value), you want the `-ed` event. The `-ing` event runs synchronously in the middle of the dispatch path and is heavier for both the framework and the reader of your code.
52
+
53
+
### Concrete Examples
54
+
55
+
```csharp
56
+
// ✅ Correct — fire-and-forget side-effect belongs on the -ed event
57
+
button.Accepted+= (_, _) =>DoTheThing ();
58
+
59
+
// ✅ Correct — actually needs to cancel, so -ing is right
60
+
button.Accepting+= (_, e) => { if (!CanProceed ()) e.Handled=true; };
61
+
62
+
// ❌ Wrong — handler ignores EventArgs; should use Accepted
63
+
button.Accepting+= (_, _) =>DoTheThing ();
64
+
```
65
+
66
+
The same rule applies to every other paired event in the framework:
67
+
68
+
| Use `-ed` (side-effect) | Use `-ing` (inspect / cancel) |
0 commit comments