Here is what I ended up doing. The example shows only the general insert handler.
var EventHandler = Base.extend({ btnClickHandler: function(){ return function (event) { event.preventDefault(); Meteor.eventhandler[event.currentTarget.id](event); } }, insert: function(event){ event.preventDefault(); var params = $('#insert-form').toJSON(); try{ window[Meteor.request.controller.capitalise()]['validateParams'](params); var ts = new Date(); params.client_updated = ts; var has_popup = params.has_popup; delete params.has_popup; window[Meteor.request.controller.capitalise()]['insert'](params, function(error, _id){ if(error){ Alert.setAlert('Error', error, 'alert-error', true, has_popup); } else { Alert.setAlert('Success', 'Record successfully created.', 'alert-success', true, has_popup); $("#insert-form").reset(); Meteor.flush(); } }); } catch(error) { Alert.setAlert('Error', error, 'alert-error', true, params.has_popup); } } }); Meteor.eventhandler = new EventHandler;
Now I just need to create descriptor templates without any significant javascript code to handle the generic events and link them as follows.
$(document).on("click", '#print', Meteor.eventhandler.btnClickHandler()); $(document).on("click", '#insert', Meteor.eventhandler.btnClickHandler()); $(document).on("click", '#remove', Meteor.eventhandler.btnClickHandler()); $(document).on("click", '#removeSubField', Meteor.eventhandler.btnClickHandler()); $(document).on("click", '#insertSubField', Meteor.eventhandler.btnClickHandler()) $(document).on("click", '#update', Meteor.eventhandler.btnClickHandler()); $(document).on("click", '#updateSubField', Meteor.eventhandler.btnClickHandler()); $(document).on("click", "#toggleActive", Meteor.eventhandler.btnClickHandler()); $(document).on("click", "#toggleChild", Meteor.eventhandler.btnClickHandler());
Now I do not need to write any template event cards for processing basic CRUD. I can create any number of handle patterns if / route matches the collection name. Although from time to time I do some complex conversions. Basically, an event handler generates events based on the aka request.controller route into the collection and abstracts it through a common client / server data model to verify and even control access along with what exists in Meteor.
It seems to work well and significantly reduced my code base. I have dozens of collections in which I did not have to write event map handlers, because the main CRUD is processed, but abstracted enough so that I can configure checks, security, and other health checks in the client / server shared data model.