Class: React::ReduxComponent::AppStoreDefaults

Inherits:
Object
  • Object
show all
Defined in:
lib/react/redux_component/app_store_defaults.rb

Instance Method Summary collapse

Constructor Details

#initialize(state, component_name) ⇒ AppStoreDefaults

Returns a new instance of AppStoreDefaults.



4
5
6
7
8
9
10
11
# File 'lib/react/redux_component/app_store_defaults.rb', line 4

def initialize(state, component_name)
  @state = state
  if @state.isomorfeus_store
    @state.isomorfeus_store.merge!(application_state: {})
  else
    @state.isomorfeus_store = { application_state: {}}
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/react/redux_component/app_store_defaults.rb', line 13

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

    # check if we have a component local state value
    if @state.isomorfeus_store[:application_state].has_key?(key)
      return @state.isomorfeus_store[:application_state][key]
    end
  end
  nil
end

Instance Method Details

#to_hObject



33
34
35
# File 'lib/react/redux_component/app_store_defaults.rb', line 33

def to_h
  @state.isomorfeus_store[:application_state]
end