glendix/binding
Provides binding operations for Glendix.
import gleam/result
import glendix/binding
import redraw
import redraw/dom/attribute
pub fn pie_chart(
attrs attrs: List(attribute.Attribute),
children children: List(redraw.Element),
) -> Result(redraw.Element, binding.BindingError) {
use module <- result.try(binding.module("recharts"))
use component <- result.try(binding.resolve(module, "PieChart"))
Ok(binding.element(component, attrs, children))
}
Types
Describes a missing JavaScript binding.
pub type BindingError {
ModuleWasNotFound(name: String, reason: String)
ExportWasNotFound(name: String, reason: String)
}
Constructors
-
ModuleWasNotFound(name: String, reason: String)The requested JavaScript module is not registered.
-
ExportWasNotFound(name: String, reason: String)The requested export is not available from the module.
Describes a configured module initialization failure.
pub type InitializationError {
InitializationCouldNotStart(
module_name: String,
export_name: String,
reason: String,
)
InitializationRejected(
module_name: String,
export_name: String,
reason: String,
)
}
Constructors
-
InitializationCouldNotStart( module_name: String, export_name: String, reason: String, )The configured initializer could not be invoked as a Promise operation.
-
InitializationRejected( module_name: String, export_name: String, reason: String, )The initializer Promise rejected before the module became ready.
Reports the current caller-owned module initialization phase.
pub type InitializationStatus {
Uninitialized
Initializing
Ready
Failed(error: InitializationError)
}
Constructors
-
UninitializedThe configured initializer has not started.
-
InitializingOne initializer Promise is currently shared by every consumer.
-
ReadyThe module is safe for rendering and non-React API use.
-
Failed(error: InitializationError)The most recent initialization attempt failed.
Represents one JavaScript component exported by a configured module.
pub type JsComponent
Caller-owned one-flight state for one configured JavaScript module.
pub opaque type ModuleInitialization
Values
pub fn element(
component component: JsComponent,
attributes attributes: List(attribute.Attribute),
children children: List(redraw.Element),
) -> redraw.Element
Creates an element from an external component, attributes, and children.
pub fn element_(
component component: JsComponent,
children children: List(redraw.Element),
) -> redraw.Element
Creates an element from an external component and children.
pub fn initialization(
module module: JsModule,
) -> ModuleInitialization
Creates caller-owned initialization state for a configured module.
Modules without an initializer begin in Ready; configured initializers
begin in Uninitialized.
pub fn initialization_effect(
initialization initialization: ModuleInitialization,
to_message to_message: fn(Result(Nil, InitializationError)) -> message,
) -> #(ModuleInitialization, effect.Effect(message))
Starts or reuses initialization and dispatches its result as a Lustre effect.
pub fn initialization_status(
initialization initialization: ModuleInitialization,
) -> InitializationStatus
Reports the current phase without exposing the shared Promise.
pub fn initialize(
initialization initialization: ModuleInitialization,
) -> #(
ModuleInitialization,
promise.Promise(Result(Nil, InitializationError)),
)
Starts or reuses the module’s one-flight initialization attempt.
The returned lifecycle must replace the caller’s previous value. A caller
records the Promise result with settle_initialization before starting a
later retry.
pub fn initialized_module(
initialization initialization: ModuleInitialization,
) -> option.Option(JsModule)
Returns the module only after it is ready for every configured consumer.
pub fn module(
name name: String,
) -> Result(JsModule, BindingError)
Returns a JavaScript module handle by name.
pub fn reset_initialization(
initialization initialization: ModuleInitialization,
) -> ModuleInitialization
Resets a settled configured initializer for an explicit later attempt.
An in-flight attempt is never reset because its eventual completion would otherwise race a newer attempt. Modules without an initializer remain ready.
pub fn resolve(
module module: JsModule,
name name: String,
) -> Result(JsComponent, BindingError)
Resolves an exported JavaScript value from a module handle.
pub fn settle_initialization(
initialization initialization: ModuleInitialization,
with outcome: Result(Nil, InitializationError),
) -> ModuleInitialization
Records one attempt’s completion in caller-owned lifecycle state.
Calls outside Initializing are ignored so duplicate or stale completion
messages cannot replace an already-settled state.
pub fn use_initialization(
attempt attempt: promise.Promise(
Result(Nil, InitializationError),
),
) -> Result(Nil, InitializationError)
Reads an initialization attempt from a React Suspense boundary.
Store the lifecycle returned by initialize outside the render call so
rerenders reuse the same attempt.
pub fn void_element(
component component: JsComponent,
attributes attributes: List(attribute.Attribute),
) -> redraw.Element
Creates an element from an external component without children.