abstract class Components::StatefulComponent

Overview

Base class for stateful components These components maintain internal state and can respond to user interactions

Direct Known Subclasses

Defined in:

components/base/stateful_component.cr

Constructors

Instance Method Summary

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

Constructor Detail

def self.new(**attrs) #

[View source]

Instance Method Detail

def cacheable? : Bool #

Stateful components should not be cached by default


[View source]
def changed? : Bool #

Check if component has changed


[View source]
def get_state(key : String) : JSON::Any | Nil #

Get a state value


[View source]
def mark_changed! #

Mark component as changed


[View source]
def reset_changed #

Alias for consistency


[View source]
def reset_changed! #

Reset changed flag


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

Set a state value


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

Set state from various types


[View source]
def set_state(key : String, value : Int32) #

[View source]
def set_state(key : String, value : Int64) #

[View source]
def set_state(key : String, value : Float32) #

[View source]
def set_state(key : String, value : Float64) #

[View source]
def set_state(key : String, value : Bool) #

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

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

[View source]
def state : Hash(String, JSON::Any) #

Get the current state as a hash


[View source]
def state_to_json : JSON::Any #

Convert state to JSON


[View source]