class UI::State(T)

Overview

Type-safe reactive state container.

When the value changes, all registered listeners are notified with the old and new values. Listeners are NOT called when the same value is assigned (equality check via !=).

Example: counter = UI::State(Int32).new(0) counter.on_change { |old_val, new_val| puts "#{old_val} -> #{new_val}" } counter.value = 1 # prints "0 -> 1" counter.value = 1 # no output (same value)

Defined in:

ui/state.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(value : T) #

[View source]

Instance Method Detail

def on_change(&block : T, T -> Nil) : Nil #

[View source]
def remove_listeners : Nil #

[View source]
def value : T #

[View source]
def value=(new_value : T) : T #

[View source]