Code Renaissance is about building great teams and great software. By exploring best practices, team interactions, design, testing and related skills Code Renaissance strives to help you create the team and codebase that you've always wanted.

Releasing knockout.viewmodel plugin 1.0

If you've used knockout.js then you are familiar with the knockout.mapping plugin for creating viewmodels. As awesome as knockout is, the mapping plugin is what made it really practical to use. Unfortunately as I've tried to knockout in business applications I've found the mapping plugin had a few problems:

  • It was slow on large view models, particularly in older browsers(IE7/8) and on large arrays.
  • Creating viewmodels wasn't a one step process... after calling mapping you'd then have to extend the viewmodel further. 
  • It provided no easy way to organize the viewmodel creation code which becomes a problem on larger viewmodels.
  • It didn't allow much customization in how the viewmodel was created and what customization there was was confusing and not intuitive to use.

I've been working the past couple of months to address these issues by creating a new mapping plugin. The knockout.viewmodel plugin uses recursive algorithms to create viewmodels over 85% faster than the original mapping plugin and was designed to allow  viewmodel creation, extension, and management to take place entirely through the plugin. This provides a natural organization to the code. 

Documentation and downloads for the javascript plugin can be found here and it is currently hosted on GitHub. It can also be found on Nuget and can be installed through visual studio by searching Nuget for "knockout.viewmodel".

I have already created an extensive set of unit tests for the project. These include unit test that were run against the current version of knockout.mapping for basic mapping. This means that without mapping options specified knockout.viewmodel should generate identical viewmodels to knockout.mapping.

In case you find any problems with the plugin I have created a jsfiddle unit test that you can modify, save and submit as part of a new issue ticket. I plan to add unit tests to the test suite for all issues. I really could not have taken this as far as I have without unit tests and they will definitely be a permanent part of the project. 

Mad props to QUnit Team for their phenomenal javascript unit testing framework, to the GitHub Team for their recently released GitHub for Windows, and to Steve Sanderson for creating knockout and knockout.mapping, which has revolutionized the way I create user interfaces for the web.

This is my first venture into open source so I'm sure I have many mistakes ahead of me. I appreciate the patience of the community and any help you can provide. Please let me know what you think.

And in closing... Merry Christmas everyone! We just crossed into Christmas day here so consider this an early Christmas gift... it's nice to finally give something back to the community.