sprocket

Types

pub type CSRFValidator =
  fn(String) -> Result(Nil, Nil)
pub type PropList =
  List(#(String, String))
pub type Response(p) {
  Joined(spkt: Sprocket(p))
  Empty
}

Constructors

  • Joined(spkt: Sprocket(p))
  • Empty
pub type Sprocket(p) {
  Sprocket(
    component: FunctionalComponent(p),
    initialize_props: fn(Option(PropList)) -> p,
    runtime: Option(Runtime),
    ws_send: WSSend,
    csrf_validator: CSRFValidator,
    opts: Option(SprocketOpts),
  )
}

Constructors

  • Sprocket(
      component: FunctionalComponent(p),
      initialize_props: fn(Option(PropList)) -> p,
      runtime: Option(Runtime),
      ws_send: WSSend,
      csrf_validator: CSRFValidator,
      opts: Option(SprocketOpts),
    )
pub type SprocketOpts {
  SprocketOpts(debug: Bool)
}

Constructors

  • SprocketOpts(debug: Bool)
pub type WSSend =
  fn(String) -> Result(Nil, Nil)

Functions

pub fn cleanup(spkt: Sprocket(a)) -> Option(Nil)

Cleanup a sprocket. This function is called when a websocket is closed. It will find the sprocket that is associated with the websocket and stop it.

Its important to call this function when the websocket connection is terminated.

pub fn handle_ws(
  spkt: Sprocket(a),
  msg: String,
) -> Result(Response(a), String)

Handle a message from the websocket. This function is called when a message is received from the websocket. It will find the sprocket that is associated with the websocket and pass the message to the sprocket. The sprocket will then handle the message and send a response back to the websocket.

pub fn new(
  component: fn(Context, a) -> #(Context, Element),
  initialize_props: fn(Option(List(#(String, String)))) -> a,
  ws_send: fn(String) -> Result(Nil, Nil),
  csrf_validator: fn(String) -> Result(Nil, Nil),
  opts: Option(SprocketOpts),
) -> Sprocket(a)
pub fn render(el: Element, r: Renderer(a)) -> a
Search Document