Important Development Techniques New to Me

Generating MVC View Models from Arrays Generated by jQuery

Many times on my latest work-for-hire project I’ve been reluctantly adding a new MVC View Model to the build. I don’t want to be one of those developers slapping redundant clutter out of ignorance and the fear of being perceived of as “too slow.” And it is time consuming to write a View Model—especially for an HTML form with several dozen data points.

What makes me feel just a little bit better is the fact that a View Model needs to be redundant for these very powerful reasons:

Getting JavaScript loaded and running is ridiculously difficult. In very large, complex clients $(document).ready() is not enough. My intent as a programmer is to compose logic into discrete units that are as independent as possible. This makes maintaining the code easier and it allows new developers to not freak out with the fear of breaking something somewhere in the mysterious deep… Without something like $(document).ajaxComplete(), the level of independence would decrease—as I would be tempted to pack more and more dependencies into the $(document).ready() function block as the client got larger and larger. This is what my $(document).ajaxComplete() pattern looks like today: $(document).ajaxComplete(function (event, xhr, options) { if (options.url.indexOf('/MyMvcRoute') !== -1) { //Visuals for each panel: $.rx.panels(); $.rx.panelOne(); $.rx.panelTwo(); $.rx.panelThree(); }); } });### Related Links

rasx()