Book Image

KNOCKOUTJS BLUEPRINTS

By : Carlo Russo
Book Image

KNOCKOUTJS BLUEPRINTS

By: Carlo Russo

Overview of this book

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

Preface

In the past five years, almost everyone working on web applications has used jQuery; but when you start working with a more complex app, you understand how difficult it is to work in such a low-level way. This is the reason behind KnockoutJS—to help you to build Rich Web Application by thinking in a high-level way, with models and not worrying about the DOM anymore. In this way, you can think about products to show, user profiles, and working days, not about table rows and columns, and you can scale up in complexity easily.

This book starts with a simple project to show you how to use all the basic features of KnockoutJS, then it will go through four other projects, to teach you how to use this library in different contexts.

The goal of this book is to teach you how to create fully testable web applications from real-world solutions with the powerful data-binding offered by KnockoutJS, how to bind all the components of a web application together—no matter how big it is, how to create new reusable components by yourself, and how to integrate external libraries easily.

What this book covers

Chapter 1, From Idea to Realization, introduces you to the structure of a basic KnockoutJS application. It's a good introduction, and it shows how KnockoutJS implements the data-binding.

Chapter 2, Starting Small and Growing in a Modular Way, shows you how to realize a BookingOnline website. We'll see how to realize template and component, and we will use RequireJS to modularize our code.

Chapter 3, SPA for Timesheet Management, shows how you to realize an SPA with DurandalJS (which uses KnockoutJS as a data-binding library).

Chapter 4, Tracking Expense Using PhoneGap, goes in a different direction by using Cordova to build a hybrid mobile application. We will use KnockoutJS with jQuery Mobile and Jasmine to show you how to test a MVVM application realized with KnockoutJS.

Chapter 5, Wizard for the Public Administration, realizes another SPA, keeping in mind accessibility and SEO.

What you need for this book

Since this book is mostly about client-side code, the main tools required are a text editor and a browser. However, the realization of hybrid mobile application with Cordova needs a working Node.js installation.

You'll have to install Node.JS (http://nodejs.org), which comes with npm, the Node package manager.

It can be useful to use http-server (a node application) to serve the web application we realize, because the browsers have many limitations when you access them using the file:// protocol.

Who this book is for

If you are a JavaScript developer and already know the basics of KnockoutJS and you want to get the most out of it, then this book is for you. This book will help you transition from a small site to a large web application that is easily maintainable.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "We can include other contexts through the use of the include directive."

A block of code is set as follows:

myViewModel.categories = ko.computed(function() {
  var results = myViewModel.allCategories(),
      filterByCategory = myViewModel.selectedCategory();
  if (filterByCategory) {
    results = ko.utils.arrayFilter(results, function(category) {
      return category.name === filterByCategory;
    });
  }
  return results;
});

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

var myViewModel = {
  allCategories: ko.observableArray([]),
  selectedCategory: ko.observable(),
  selectedName: ko.observable("")
}; 

Any command-line input or output is written as follows:

# npm install –g http-server

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Here we get the starting page, with an Error loading page."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/0840OS_Graphics.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.