Class: LucidComponent::AppStoreProxy
- Inherits:
-
Object
- Object
- LucidComponent::AppStoreProxy
show all
- Defined in:
- lib/lucid_component/app_store_proxy.rb
Instance Method Summary
collapse
Constructor Details
#initialize(component_instance, access_key = 'state') ⇒ AppStoreProxy
Returns a new instance of AppStoreProxy.
3
4
5
6
7
|
# File 'lib/lucid_component/app_store_proxy.rb', line 3
def initialize(component_instance, access_key = 'state')
@native_component_instance = component_instance.to_n
@component_instance = component_instance
@access_key = access_key
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(key, *args, &block) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/lucid_component/app_store_proxy.rb', line 9
def method_missing(key, *args, &block)
@native_component_instance.JS.register_used_store_path(['application_state', key])
if `args.length > 0`
action = { type: 'APPLICATION_STATE', name: (`key.endsWith('=')` ? key.chop : key), value: args[0] }
Isomorfeus.store.dispatch(action)
else
if `this.native_component_instance[this.access_key]["isomorfeus_store"]["application_state"].hasOwnProperty(key)`
return @native_component_instance.JS[@access_key].JS[:isomorfeus_store].JS[:application_state].JS[key]
elsif @component_instance.class.default_app_store_defined && @component_instance.class.app_store.to_h.key?(key)
return @component_instance.class.app_store.to_h[key]
end
return nil
end
end
|
Instance Method Details
#dispatch(action) ⇒ Object
28
29
30
|
# File 'lib/lucid_component/app_store_proxy.rb', line 28
def dispatch(action)
Isomorfeus.store.dispatch(action)
end
|
#subscribe(&block) ⇒ Object
32
33
34
|
# File 'lib/lucid_component/app_store_proxy.rb', line 32
def subscribe(&block)
Isomorfeus.store.subscribe(&block)
end
|
#unsubscribe(unsubscriber) ⇒ Object
36
37
38
|
# File 'lib/lucid_component/app_store_proxy.rb', line 36
def unsubscribe(unsubscriber)
`unsubscriber()`
end
|