ConsoleForge 0.3.0
Elm-architecture TUI framework for .NET 8
Loading...
Searching...
No Matches
ConsoleForge.Core.Component Class Reference

Static helpers for working with IComponent and IComponent<TResult> in parent model Update methods. More...

Static Public Member Functions

static bool IsCompleted< TResult > ([NotNullWhen(false)] this IComponent< TResult >? component)
 Returns true if component has completed — i.e.

Static Public Attributes

static T Component
 Initialise a component and dispatch its startup command if any.
static ? T Next
 Delegate an IMsg to component and return the updated component (typed) alongside the optional follow-up command.

Detailed Description

Static helpers for working with IComponent and IComponent<TResult> in parent model Update methods.

These methods exist to eliminate the cast boilerplate that would otherwise be required when delegating Update calls to a typed component field:

// Without helpers:
var (next, cmd) = myPage.Update(msg);
var typed = (MyPage)next; // cast required — Update returns IModel
// With helpers:
var (next, cmd) = Component.Delegate(myPage, msg); // next is MyPage
static T Component
Initialise a component and dispatch its startup command if any.
Definition Component.cs:79

Member Function Documentation

◆ IsCompleted< TResult >()

bool ConsoleForge.Core.Component.IsCompleted< TResult > ( [NotNullWhen(false)] this IComponent< TResult >? component)
static

Returns true if component has completed — i.e.

its IComponent<TResult>.Result is non-null. Safe to call on a null reference; returns false.

Template Parameters
TResultThe component's result type.
Parameters
componentThe component to check, or null.

Member Data Documentation

◆ Component

T ConsoleForge.Core.Component.Component
static

Initialise a component and dispatch its startup command if any.

Equivalent to calling IModel.Init and passing the result to Cmd.Batch.

Template Parameters
TConcrete component type.
Parameters
componentThe component to initialise.
extraCmdsAdditional commands to batch alongside the component's own init command.
Returns
The same component reference (init is side-effect-free) and the combined startup command, or null if none.

◆ Next

? T ConsoleForge.Core.Component.Next
static

Delegate an IMsg to component and return the updated component (typed) alongside the optional follow-up command.

Returns (null, null) when component is null.

Template Parameters
TConcrete component type (must implement IComponent).
Parameters
componentThe component to update, or null.
msgThe message to process.
Returns
The updated component cast back to T and the optional ICmd to dispatch. Both are null when the component is null.
Exceptions
InvalidCastExceptionThrown if the component's Update implementation returns a different concrete type than T . Components must return this with { … } (a new instance of the same type).

The documentation for this class was generated from the following file:
  • src/ConsoleForge/Core/Component.cs