| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- using Spry;
- using Inversion;
- /**
- * SimpleCounterDemo - A basic counter demo for the Actions documentation
- *
- * Demonstrates:
- * - spry-action for same-component actions
- * - spry-target for scoped targeting
- * - State management via a singleton store
- */
- public class SimpleCounterDemo : Component {
-
- private CounterDemoStore store = inject<CounterDemoStore>();
-
- public override string markup { get {
- return """
- <div sid="counter" class="demo-counter">
- <div class="counter-display" sid="display">0</div>
- <div class="counter-controls">
- <button class="counter-btn decrement"
- spry-action=":Decrement"
- spry-target="counter">−</button>
- <button class="counter-btn increment"
- spry-action=":Increment"
- spry-target="counter">+</button>
- </div>
- </div>
- """;
- }}
-
- public override async void prepare() throws Error {
- this["display"].text_content = store.count.to_string();
- }
-
- public async override void handle_action(string action) throws Error {
- switch (action) {
- case "Increment":
- store.count++;
- break;
- case "Decrement":
- store.count--;
- break;
- }
- }
- }
- /**
- * CounterDemoStore - Singleton store to persist counter state
- */
- public class CounterDemoStore : Object {
- public int count { get; set; default = 0; }
- }
|