sprocket/context

Types

pub type AbstractFunctionalComponent =
  fn(Context, Dynamic) -> #(Context, List(Element))
pub type ComponentHooks =
  OrderedMap(Int, Hook)
pub type ComponentWip {
  ComponentWip(
    hooks: ComponentHooks,
    index: Int,
    is_first_render: Bool,
  )
}

Constructors

  • ComponentWip(
      hooks: ComponentHooks,
      index: Int,
      is_first_render: Bool,
    )
pub type Context {
  Context(
    view: Element,
    wip: ComponentWip,
    handlers: List(EventHandler),
    render_update: fn() -> Nil,
    update_hook: fn(Unique, fn(Hook) -> Hook) -> Nil,
    dispatch_event: fn(Unique, String, Option(String)) ->
      Result(Nil, Nil),
  )
}

Constructors

  • Context(
      view: Element,
      wip: ComponentWip,
      handlers: List(EventHandler),
      render_update: fn() -> Nil,
      update_hook: fn(Unique, fn(Hook) -> Hook) -> Nil,
      dispatch_event: fn(Unique, String, Option(String)) ->
        Result(Nil, Nil),
    )
pub type Dispatcher {
  Dispatcher(
    dispatch: fn(String, String, Option(String)) ->
      Result(Nil, Nil),
  )
}

Constructors

  • Dispatcher(
      dispatch: fn(String, String, Option(String)) ->
        Result(Nil, Nil),
    )
pub type Element {
  Element(
    tag: String,
    attrs: List(Attribute),
    children: List(Element),
  )
  Component(
    component: FunctionalComponent(Dynamic),
    props: Dynamic,
  )
  Debug(id: String, meta: Option(Dynamic), element: Element)
  Keyed(key: String, element: Element)
  IgnoreUpdate(element: Element)
  SafeHtml(html: String)
  Raw(text: String)
}

Constructors

  • Element(
      tag: String,
      attrs: List(Attribute),
      children: List(Element),
    )
  • Component(
      component: FunctionalComponent(Dynamic),
      props: Dynamic,
    )
  • Debug(id: String, meta: Option(Dynamic), element: Element)
  • Keyed(key: String, element: Element)
  • IgnoreUpdate(element: Element)
  • SafeHtml(html: String)
  • Raw(text: String)
pub type EventHandler {
  EventHandler(id: Unique, handler: CallbackFn)
}

Constructors

  • EventHandler(id: Unique, handler: CallbackFn)
pub type FunctionalComponent(p) =
  fn(Context, p) -> #(Context, List(Element))
pub type Updater(r) {
  Updater(send: fn(r) -> Result(Nil, Nil))
}

Constructors

  • Updater(send: fn(r) -> Result(Nil, Nil))

Functions

pub fn dispatch_event(ctx: Context, id: Unique, name: String, payload: Option(
    String,
  )) -> Result(Nil, Nil)
pub fn fetch_or_init_hook(ctx: Context, init: fn() -> Hook) -> #(
  Context,
  Hook,
  Int,
)
pub fn get_event_handler(ctx: Context, id: Unique) -> #(
  Context,
  Result(EventHandler, Nil),
)
pub fn new(view: Element, dispatcher: Option(Dispatcher)) -> Context
pub fn push_event_handler(ctx: Context, identifiable_cb: IdentifiableCallback) -> #(
  Context,
  Unique,
)
pub fn reset_for_render(ctx: Context) -> Context
pub fn update_hook(ctx: Context, hook: Hook, index: Int) -> Context
Search Document