Class: Hyalite::Component::State

Inherits:
Object
  • Object
show all
Defined in:
lib/hyalite/component.rb

Instance Method Summary collapse

Constructor Details

#initialize(component, updator, initial_state) ⇒ State

Returns a new instance of State.



213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/hyalite/component.rb', line 213

def initialize(component, updator, initial_state)
  @component = component
  @updator = updator
  @state = initial_state.clone
  initial_state.each do |key, value|
    define_singleton_method(key) do
      @state[key]
    end
    define_singleton_method(key + '=') do |value|
      @updator.enqueue_set_state(@component, key => value)
    end
  end
end

Instance Method Details

#[](key) ⇒ Object



227
228
229
# File 'lib/hyalite/component.rb', line 227

def [](key)
  @state[key]
end

#set(state) ⇒ Object



231
232
233
# File 'lib/hyalite/component.rb', line 231

def set(state)
  @state = state.clone
end

#to_hObject



235
236
237
# File 'lib/hyalite/component.rb', line 235

def to_h
  @state
end