sprocket/context

Types

pub type AbstractFunctionalComponent =
  fn(Context, Dynamic) -> #(Context, Element)
pub type Attribute {
  Attribute(name: String, value: Dynamic)
  Event(name: String, handler: IdentifiableHandler)
  ClientHook(id: Unique, name: String)
}

Constructors

  • Attribute(name: String, value: Dynamic)
  • Event(name: String, handler: IdentifiableHandler)
  • ClientHook(id: Unique, name: String)
pub type CallbackParam {
  CallbackString(value: String)
}

Constructors

  • CallbackString(value: String)
pub type CallbackResult {
  CallbackResult(deps: Option(HookDependencies))
}

Constructors

  • CallbackResult(deps: Option(HookDependencies))
pub type ClientDispatcher =
  fn(String, Option(String)) -> Result(Nil, Nil)
pub type ClientEventHandler =
  fn(String, Option(Dynamic), ClientDispatcher) -> Nil
pub type Compared(a) {
  Changed(changed: a)
  Unchanged
}

Constructors

  • Changed(changed: a)
  • Unchanged
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(IdentifiableHandler),
    render_update: fn() -> Nil,
    update_hook: fn(Unique, fn(Hook) -> Hook) -> Nil,
    dispatch_event: fn(Unique, String, Option(String)) ->
      Result(Nil, Nil),
    cuid_channel: Subject(cuid.Message),
    providers: Dict(String, Dynamic),
  )
}

Constructors

  • Context(
      view: Element,
      wip: ComponentWip,
      handlers: List(IdentifiableHandler),
      render_update: fn() -> Nil,
      update_hook: fn(Unique, fn(Hook) -> Hook) -> Nil,
      dispatch_event: fn(Unique, String, Option(String)) ->
        Result(Nil, Nil),
      cuid_channel: Subject(cuid.Message),
      providers: Dict(String, Dynamic),
    )
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 EffectCleanup =
  Option(fn() -> Nil)
pub type EffectResult {
  EffectResult(
    cleanup: EffectCleanup,
    deps: Option(HookDependencies),
  )
}

Constructors

  • EffectResult(
      cleanup: EffectCleanup,
      deps: Option(HookDependencies),
    )
pub type Element {
  Element(
    tag: String,
    attrs: List(Attribute),
    children: List(Element),
  )
  Component(
    component: FunctionalComponent(Dynamic),
    props: Dynamic,
  )
  Fragment(children: List(Element))
  Debug(id: String, meta: Option(Dynamic), element: Element)
  Keyed(key: String, element: Element)
  IgnoreUpdate(element: Element)
  Provider(key: String, value: Dynamic, element: Element)
  Text(text: String)
  Custom(kind: String, data: String)
}

Constructors

  • Element(
      tag: String,
      attrs: List(Attribute),
      children: List(Element),
    )
  • Component(
      component: FunctionalComponent(Dynamic),
      props: Dynamic,
    )
  • Fragment(children: List(Element))
  • Debug(id: String, meta: Option(Dynamic), element: Element)
  • Keyed(key: String, element: Element)
  • IgnoreUpdate(element: Element)
  • Provider(key: String, value: Dynamic, element: Element)
  • Text(text: String)
  • Custom(kind: String, data: String)
pub type FunctionalComponent(p) =
  fn(Context, p) -> #(Context, Element)
pub type HandlerFn =
  fn(Option(CallbackParam)) -> Nil
pub type Hook {
  Callback(
    id: Unique,
    callback: fn() -> Nil,
    prev: Option(CallbackResult),
  )
  Memo(id: Unique, value: Dynamic, prev: Option(MemoResult))
  Effect(
    id: Unique,
    effect: fn() -> EffectCleanup,
    trigger: HookTrigger,
    prev: Option(EffectResult),
  )
  Handler(id: Unique, handler_fn: HandlerFn)
  Reducer(id: Unique, reducer: Dynamic, cleanup: fn() -> Nil)
  State(id: Unique, value: Dynamic)
  Client(
    id: Unique,
    name: String,
    handle_event: Option(ClientEventHandler),
  )
}

Constructors

  • Callback(
      id: Unique,
      callback: fn() -> Nil,
      prev: Option(CallbackResult),
    )
  • Memo(id: Unique, value: Dynamic, prev: Option(MemoResult))
  • Effect(
      id: Unique,
      effect: fn() -> EffectCleanup,
      trigger: HookTrigger,
      prev: Option(EffectResult),
    )
  • Handler(id: Unique, handler_fn: HandlerFn)
  • Reducer(id: Unique, reducer: Dynamic, cleanup: fn() -> Nil)
  • State(id: Unique, value: Dynamic)
  • Client(
      id: Unique,
      name: String,
      handle_event: Option(ClientEventHandler),
    )
pub type HookDependencies =
  List(Dynamic)
pub type HookTrigger {
  OnMount
  OnUpdate
  WithDeps(deps: HookDependencies)
}

Constructors

  • OnMount
  • OnUpdate
  • WithDeps(deps: HookDependencies)
pub type IdentifiableHandler {
  IdentifiableHandler(id: Unique, handler_fn: HandlerFn)
}

Constructors

  • IdentifiableHandler(id: Unique, handler_fn: HandlerFn)
pub type MemoResult {
  MemoResult(deps: Option(HookDependencies))
}

Constructors

  • MemoResult(deps: Option(HookDependencies))
pub type Updater(r) {
  Updater(send: fn(r) -> Result(Nil, Nil))
}

Constructors

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

Functions

pub fn callback_param_from_string(value: String) -> CallbackParam
pub fn compare_deps(
  prev_deps: List(Dynamic),
  deps: List(Dynamic),
) -> Compared(List(Dynamic))
pub fn dep(dependency: a) -> Dynamic
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(IdentifiableHandler, Nil))
pub fn new(
  view: Element,
  cuid_channel: Subject(Message),
  dispatcher: Option(Dispatcher),
  render_update: fn() -> Nil,
  update_hook: fn(Unique, fn(Hook) -> Hook) -> Nil,
) -> Context
pub fn prepare_for_reconciliation(ctx: Context) -> Context
pub fn provider(
  key: String,
  value: a,
  element: Element,
) -> Element
pub fn push_event_handler(
  ctx: Context,
  identifiable_cb: IdentifiableHandler,
) -> #(Context, Unique)
pub fn update_hook(
  ctx: Context,
  hook: Hook,
  index: Int,
) -> Context
Search Document