Class: LucidComponent::ClassStoreProxy

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

Instance Method Summary collapse

Constructor Details

#initialize(component_name, native = nil) ⇒ ClassStoreProxy

Returns a new instance of ClassStoreProxy.



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

def initialize(component_name, native = nil)
  @component_name = component_name
  @native = native
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/isomorfeus_preact/lucid_component/class_store_proxy.rb', line 16

def method_missing(key, *args, &block)
  if `args.length > 0`
    # set class state, simply a dispatch
    action = { type: 'CLASS_STATE', class: @component_name, name: (`key.endsWith('=')` ? key.chop : key), value: args[0] }
    Isomorfeus.store.collect_and_defer_dispatch(action)
  else
    # get class state
    # check if we have a component local state value
    if `#@native?.props?.iso_store?.class_state?.[#@component_name]?.hasOwnProperty?.(key)`
      return `#@native.props.iso_store.class_state[#@component_name][key]`
    else
      a_state = Isomorfeus.store.get_state
      if a_state.key?(:class_state) && a_state[:class_state].key?(@component_name) && a_state[:class_state][@component_name].key?(key)
        return a_state[:class_state][@component_name][key]
      end
    end
    # otherwise return nil
    return nil
  end
end

Instance Method Details

#[](key) ⇒ Object



8
9
10
# File 'lib/isomorfeus_preact/lucid_component/class_store_proxy.rb', line 8

def [](key)
  method_missing(key)
end

#[]=(key, value) ⇒ Object



12
13
14
# File 'lib/isomorfeus_preact/lucid_component/class_store_proxy.rb', line 12

def []=(key, value)
  method_missing(key, value)
end