abstract class Components::Reactive::ReactiveComponent

Overview

Base class for components that support real-time updates via WebSocket

Direct Known Subclasses

Defined in:

components/reactive/reactive_component.cr

Macro Summary

Instance Method Summary

Instance methods inherited from class Components::StatefulComponent

cacheable? : Bool cacheable?, changed? : Bool changed?, get_state(key : String) : JSON::Any | Nil get_state, mark_changed! mark_changed!, reset_changed reset_changed, reset_changed! reset_changed!, set_state(key : String, value : JSON::Any) : Nil
set_state(key : String, value : String)
set_state(key : String, value : Int32)
set_state(key : String, value : Int64)
set_state(key : String, value : Float32)
set_state(key : String, value : Float64)
set_state(key : String, value : Bool)
set_state(key : String, value : Array(JSON::Any))
set_state(key : String, value : Hash(String, JSON::Any))
set_state
, state : Hash(String, JSON::Any) state, state_to_json : JSON::Any state_to_json

Constructor methods inherited from class Components::StatefulComponent

new(**attrs) new

Instance methods inherited from class Components::Component

<<(child : Component | Elements::HTMLElement | String | Elements::RawHTML) : self <<, [](name : String) : String | Nil [], []=(name : String, value : String) : String []=, add_children(*children : Component | Elements::HTMLElement | String | Elements::RawHTML) : self add_children, attributes : Hash(String, String) attributes, build(&block : self -> Nil) : self build, children : Array(Component | Elements::HTMLElement | String | Elements::RawHTML) children, component_id : String component_id, render : SafeHTML render, render_content : String render_content, render_safe_content : SafeHTML render_safe_content, to_raw_html : Elements::RawHTML to_raw_html, to_s(io : IO) : Nil to_s

Constructor methods inherited from class Components::Component

new(**attrs) new

Macros inherited from class Components::Component

component_css(css_string) component_css

Macro Detail

macro on_action(action_name, &block) #

Define client-side action handler


[View source]
macro on_event(event_name, &block) #

Subscribe to server-side events


[View source]

Instance Method Detail

def auto_update : Bool #

Whether this component should auto-update on state changes


[View source]
def auto_update=(auto_update : Bool) #

Whether this component should auto-update on state changes


[View source]
def broadcast_update : Nil #

Broadcast update to all sessions with this component


[View source]
def handle_action(action : String, data : JSON::Any) : Nil #

Handle incoming actions from client


[View source]
def push_update : Nil #

Send update to all connected clients


[View source]
def register : Nil #

Register this component with the reactive handler


[View source]
def render : SafeHTML #

Override render to include reactive data attributes


[View source]
def set_state(key : String, value : JSON::Any) : Nil #

Override state setters to trigger updates


[View source]
def unregister : Nil #

Unregister this component


[View source]
def update_state(&block : -> Nil) : Nil #

Batch state updates


[View source]