Class: LucidComponent::AppStoreProxy

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

Instance Method Summary collapse

Constructor Details

#initialize(native) ⇒ AppStoreProxy

Returns a new instance of AppStoreProxy.



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

def initialize(native)
  @native = native
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/isomorfeus_preact/lucid_component/app_store_proxy.rb', line 15

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

Instance Method Details

#[](key) ⇒ Object



7
8
9
# File 'lib/isomorfeus_preact/lucid_component/app_store_proxy.rb', line 7

def [](key)
  method_missing(key)
end

#[]=(key, value) ⇒ Object



11
12
13
# File 'lib/isomorfeus_preact/lucid_component/app_store_proxy.rb', line 11

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