| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- 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);
- }
- }
- /**
- * Entrypoint for the guarded dashboard page. The page is protected by a
- * client-side `stm-guard`; the entrypoint just greets the held `auth` slot.
- */
- public class DashboardEntrypoint : StatumEntrypoint {
- public override async DirectiveBuilder handle() throws GLib.Error {
- return directives().notify("info", "Welcome to your dashboard");
- }
- }
- }
|