4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/isomorfeus/data/reducer.rb', line 4
def self.add_reducer_to_store
data_reducer = Redux.create_reducer do |prev_state, action|
action_type = action[:type]
if action_type.JS.startsWith('DATA_')
case action_type
when 'DATA_STATE'
if action.key?(:set_state)
action[:set_state]
else
prev_state
end
when 'DATA_LOAD'
prev_state.deep_merge(action[:data])
else
prev_state
end
else
prev_state.nil? ? {} : prev_state
end
end
Redux::Store.preloaded_state_merge!(data_state: {})
Redux::Store.add_reducer(data_state: data_reducer)
end
|