Durandal is a client side MV* framework which means it will give your application structure to keep everything neatly organized with views, models etc. It is also an SPA oriented framework and what this means is that you get routing, application state management and easy to maintain and compose layout of your choice. Another strong point of this particular framework is the fact that it does not reinvent the wheel, meaning that it utilizes popular libraries you are likely to already know and love:
Knockout for its awesome bindings
Bootstrap as the default UI/CSS framework
It also provides seamless async programing using “Promises”
All this and more makes learning Durandal quick and painless as you probably already know most of the building blocks. What Durandal adds is a thin framework that wraps mentioned libraries and a few additional/optional things to aid your application in areas of maintainability and extendibility.
I think it’s time for some code now so a simple view model straight from the Hot Towel template should demonstrate the elegance and simplicity you can see throughout the Durandal framework.
<span style="color: green;">// use service to execute a server call to get our data</span>
<span style="color: blue;">return</span>vm;
As you can see we have a basic revealing modules pattern here. VM is the object which can be referenced in other modules and will be backing an HTML view. The “active” function is going to be called by the framework whenever a user activates/accesses the “Company” view so it’s a great place for loading your data or do any other kind of initialization logic for the views. Notice that in line 4 we are requesting the companies module/service (it doesn’t matter how you call it as it is basically shaped the same as the view model but obviously provides different functionality). Durandal with the help of RequireJS promotes this modularity which so many applications these days are lacking.
Templates and resources
Durandal is one of those small things that really make a difference. Try out the sample, see how little there is to it and imagine how easily it could support large complex applications keeping them organized thus maintainable and a joy to code. Feel free to leave any comments or your experience with Durandal.