Class: LucidComponent::ComponentInstanceStoreDefaults

Inherits:
Object
  • Object
show all
Defined in:
lib/lucid_component/component_instance_store_defaults.rb

Instance Method Summary collapse

Constructor Details

#initialize(state, component_name) ⇒ ComponentInstanceStoreDefaults

Returns a new instance of ComponentInstanceStoreDefaults.



3
4
5
6
# File 'lib/lucid_component/component_instance_store_defaults.rb', line 3

def initialize(state, component_name)
  @state = {}
  @component_name = component_name
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(key, *args, &block) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/lucid_component/component_instance_store_defaults.rb', line 8

def method_missing(key, *args, &block)
  if `args.length > 0`
    # set initial class state
    key = key.chop if `key.endsWith('=')`
    @state[key] = args[0]
    current_state = Isomorfeus.store.get_state
    if !(current_state[:component_state].key?(@component_name) &&
      current_state[:component_state][@component_name].key?(:instance_defaults) &&
      current_state[:component_state][@component_name][:instance_defaults].key?(key))
      Isomorfeus.store.dispatch(type: 'COMPONENT_CLASS_STATE', class: @component_name, name: :instance_defaults, value: { key => args[0]})
    end
  else
    # get class state

    # check if we have a component local state value

    if @state.key?(key)
      return @state[key]
    end
  end
  nil
end

Instance Method Details

#to_hObject



31
32
33
# File 'lib/lucid_component/component_instance_store_defaults.rb', line 31

def to_h
  @state
end