views/mdc/components/event.erb in voom-presenters-0.1.13 vs views/mdc/components/event.erb in voom-presenters-0.2.0

- old
+ new

@@ -1,17 +1,13 @@ <% if events data_events = events.map do |event| [event.event, event.actions.map do |action| - additional_options = case action.type.to_s - when 'replaces' then - {grid_nesting:@grid_nesting, __parent_id__: parent_id} - when 'update', 'post', 'delete', 'autocomplete' then - {__parent_id__: parent_id} - else - {} - end - [action.type, action.url, action.options.to_h.merge(additional_options), action.params.to_h] + require_relative "actions/#{action.type}" + # Deligate the action data to each action class + # [Type, URL, Options, Params] these are passed into javascript event/action class constructors + # Only the type need be canonical, the rest is defined between this class and its javascript + Object.const_get("::WebClient::Actions::#{inflector.camelize(action.type)}").new.call(action, parent_id, @grid_nesting) end, {once: false}] end %> data-events = '<%= data_events.to_json %>' <% end %>