tardis
Tardis is in charge of being your good debugger friend, able to navigate accross time and space! Just instanciate it, and use it in your application.
import gleam/int
import lustre
import lustre/element/html
import lustre/event
import tardis
pub fn main() {
let assert Ok(main) = tardis.single("main")
lustre.application(init, update, view)
|> tardis.wrap(with: main)
|> lustre.start("#app", Nil)
|> tardis.activate(with: main)
}
fn init(_) {
0
}
fn update(model, msg) {
case msg {
Incr -> model + 1
Decr -> model - 1
}
}
fn view(model) {
let count = int.to_string(model)
html.div([], [
html.button([event.on_click(Incr)], [html.text(" + ")]),
html.p([], [html.text(count)]),
html.button([event.on_click(Decr)], [html.text(" - ")])
])
}
Types
Represents the instance for an application. It should be used within one and
only one application. You can get the instance by using application
or single
.
pub opaque type Instance
Functions
pub fn activate(
result: Result(fn(Action(a, b)) -> Nil, c),
with instance: Instance,
) -> Result(fn(Action(a, b)) -> Nil, c)
Activate the debugger of the application. activate
should be run to let
the debugger being able to rewind time. It should be executed on the exact
same instance that has been wrapped.
fn main() {
let assert Ok(instance) = tardis.single("main")
lustre.application(init, update, view)
|> tardis.wrap(with: instance)
|> lustre.start()
|> tardis.activate(with: instance)
}
pub fn application(instance: Tardis, name: String) -> Instance
Creates the application debugger from the tardis. Should be run once,
at the start of the application. It can be skipped when using single
.
pub fn setup() -> Result(Tardis, Error)
Creates the tardis. Should be run once, at the start of the application.
It can be skipped when using single
.
pub fn single(name: String) -> Result(Instance, Error)
Directly creates a tardis instance for a single application.
Replaces setup
and application
in a single application context.
pub fn wrap(
application: App(a, b, c),
with instance: Instance,
) -> App(a, b, c)
Wrap a lustre application with the debugger. The debugger will never interfere with your application by itself. You can directly chain your application with this function.
fn main() {
let assert Ok(instance) = tardis.single("main")
lustre.application(init, update, view)
|> tardis.wrap(with: instance)
}