Optional Language Bindings

View Source

The core package is plain Erlang so Erlang, Elixir, Gleam, LFE, and other BEAM languages can call the same datastar_beam module.

The files in bindings/ are optional starter wrappers. They are useful in applications, examples, or future companion packages, but they should not make the Erlang core depend on Elixir or Gleam build tools.

bindings/ is also excluded from the datastar_beam Hex package. Treat it as repository documentation/example source, or copy it into future wrapper packages such as datastar_beam_gleam and datastar_beam_elixir.

Elixir

Elixir can call the Erlang module directly:

:datastar_beam.patch_signals(%{"count" => 1})

The optional wrapper in bindings/elixir/lib/datastar_beam.ex gives Elixir callers a normal module name, default arguments, and typespecs:

DatastarBeam.patch_signals(%{"count" => 1})
DatastarBeam.patch_elements("<div id=\"count\">1</div>", selector: "#count")

Elixir has two type-related systems to keep in mind:

  • Gradual set-theoretic type warnings are being added to the compiler.
  • @spec and @type typespecs are still useful for documentation and Dialyzer, but they are distinct from the new compiler type system.

That means the wrapper helps editor docs, Dialyzer, and readability. It does not make the Erlang core require Elixir, and it does not turn the core API into a statically enforced cross-language interface.

Gleam

Gleam can call Erlang modules with @external, but those calls otherwise live at the interop boundary:

@external(erlang, "datastar_beam", "patch_signals")
fn patch_signals(signals: String) -> Dynamic

The optional wrapper in bindings/gleam/src/datastar_beam.gleam hides the Dynamic return value for common event/action builders and converts the returned iodata to String:

import datastar_beam

pub fn render() {
  datastar_beam.patch_signals("{\"count\":1}")
}

The current wrapper keeps options minimal. For advanced calls that pass Erlang maps or proplists, a dedicated Gleam companion package can model a small typed options API and encode it for datastar_beam.