| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- using Statum;
- using Invercargill;
- using Invercargill.DataStructures;
- namespace Example {
- /**
- * Private data carried by the bump-counter action (strongly typed). The
- * framework seals/reads it via GObject introspection — no mapper.
- */
- public class CounterPrivate : Object {
- public int delta { get; set; }
- }
- /**
- * Entrypoint for the home page.
- *
- * Demonstrates authoring action references (one with typed private data) and
- * embedding them in state so the client can invoke them via `stm-action`,
- * then returning them with the fluent directive builder.
- */
- public class HomeEntrypoint : StatumEntrypoint {
- public override async DirectiveBuilder handle() throws GLib.Error {
- // A counter slot whose public data carries a `bump` action reference
- // sealed with typed private data ({delta: 1}).
- var counter_public = new PropertyDictionary();
- counter_public.set_native<int>("value", 0);
- var bump_private = new CounterPrivate();
- bump_private.delta = 1;
- counter_public["bump"] = action_registry
- .author_private<BumpCounterAction, CounterPrivate>(bump_private)
- .to_element();
- var counter_slot = state_service.new_slot(Scope.PAGE, new State() {
- type_name = "counter",
- public_data = counter_public,
- private_data = new PropertyDictionary()
- });
- // A page slot whose public data carries a private-less `login`
- // action reference.
- var page_public = new PropertyDictionary();
- page_public["login"] = action_registry.author<LoginAction>().to_element();
- var page_slot = state_service.new_slot(Scope.PAGE, new State() {
- type_name = "page",
- public_data = page_public,
- private_data = new PropertyDictionary()
- });
- return directives().set(counter_slot).set(page_slot);
- }
- }
- }
|