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(HookId), name: String)
}
Constructors
-
Attribute(name: String, value: Dynamic)
-
Event(name: String, handler: IdentifiableHandler)
-
ClientHook(id: Unique(HookId), name: 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(HookId), fn(Hook) -> Hook) -> Nil,
emit: fn(Unique(HookId), 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(HookId), fn(Hook) -> Hook) -> Nil, emit: fn(Unique(HookId), String, Option(String)) -> Result(Nil, Nil), cuid_channel: Subject(cuid.Message), providers: Dict(String, Dynamic), )
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 EventEmitter =
fn(String, String, Option(String)) -> Result(Nil, Nil)
pub type FunctionalComponent(p) =
fn(Context, p) -> #(Context, Element)
pub type Hook {
Callback(
id: Unique(HookId),
callback: fn() -> Nil,
prev: Option(CallbackResult),
)
Memo(
id: Unique(HookId),
value: Dynamic,
prev: Option(MemoResult),
)
Effect(
id: Unique(HookId),
effect: fn() -> EffectCleanup,
deps: HookDependencies,
prev: Option(EffectResult),
)
Handler(id: Unique(HookId), handler_fn: HandlerFn)
Reducer(
id: Unique(HookId),
reducer: Dynamic,
cleanup: fn() -> Nil,
)
State(id: Unique(HookId), value: Dynamic)
Client(
id: Unique(HookId),
name: String,
handle_event: Option(ClientEventHandler),
)
}
Constructors
-
Callback( id: Unique(HookId), callback: fn() -> Nil, prev: Option(CallbackResult), )
-
Memo( id: Unique(HookId), value: Dynamic, prev: Option(MemoResult), )
-
Effect( id: Unique(HookId), effect: fn() -> EffectCleanup, deps: HookDependencies, prev: Option(EffectResult), )
-
Handler(id: Unique(HookId), handler_fn: HandlerFn)
-
Reducer( id: Unique(HookId), reducer: Dynamic, cleanup: fn() -> Nil, )
-
State(id: Unique(HookId), value: Dynamic)
-
Client( id: Unique(HookId), name: String, handle_event: Option(ClientEventHandler), )
pub type HookDependencies =
List(Dynamic)
pub type IdentifiableHandler {
IdentifiableHandler(id: Unique(HookId), handler: HandlerFn)
}
Constructors
-
IdentifiableHandler(id: Unique(HookId), handler: HandlerFn)
pub type MemoResult {
MemoResult(deps: Option(HookDependencies))
}
Constructors
-
MemoResult(deps: Option(HookDependencies))
Functions
pub fn compare_deps(
prev_deps: List(Dynamic),
deps: List(Dynamic),
) -> Compared(List(Dynamic))
pub fn emit_event(
ctx: Context,
id: Unique(HookId),
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(HookId),
) -> #(Context, Result(IdentifiableHandler, Nil))
pub fn new(
view: Element,
cuid_channel: Subject(Message),
emitter: Option(
fn(String, String, Option(String)) -> Result(Nil, Nil),
),
render_update: fn() -> Nil,
update_hook: fn(Unique(HookId), fn(Hook) -> Hook) -> Nil,
) -> Context
pub fn prepare_for_reconciliation(ctx: Context) -> Context
pub fn push_event_handler(
ctx: Context,
identifiable_cb: IdentifiableHandler,
) -> #(Context, Unique(HookId))
pub fn update_hook(
ctx: Context,
hook: Hook,
index: Int,
) -> Context