Book Image

Mastering KnockoutJS

By : Timothy Moran
Book Image

Mastering KnockoutJS

By: Timothy Moran

Overview of this book

Table of Contents (16 chapters)
Mastering KnockoutJS
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating small modules


Creating smaller modules makes unit testing simpler and reduces the effort required to understand the code for others who have to read it. When deciding whether or not to add functionalities to a module or split it off into a new one, keep the single responsibility principle in mind.

This is a bit of a balancing act. If you have a RESTful API for your JavaScript application, then creating modules to abstract away the individual URLs by providing methods for them is a good idea. Having a single dataService module that contains all of the URLs for the whole application, though, will result in a very large module in even medium-sized applications. On the other hand, having a service module for each individual route will produce an even larger number of files. This will make unit testing and maintenance harder, it won't make it easier. The best course is to group the routes into modules by functionality. In the case of REST URLs, grouping them by resource produces a very...