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

Using service modules


Viewmodels should not contain all of your application code even in small applications. When possible, code should be broken out into non-viewmodel modules that encapsulate the work and can be reused. These modules are often called services.

For example, a viewmodel that gets data from the server doesn't need to know how that operation is handled, whether it uses jQuery's AJAX method, a websocket, or some other retrieval method. Putting this logic into a data service module not only makes it reusable by other viewmodels, it makes unit testing easier by limiting the scope of each object to its own work. The driving philosophy here is the single responsibility principle.