Building a Single Page Web Application with KnockoutJS

Create a complete and structured single page application by doing more with less code
5.0 (1 rating)
Instead of using a simple lifetime average, Udemy calculates a
course's star rating by considering a number of different factors
such as the number of ratings, the age of ratings, and the
likelihood of fraudulent ratings.
37 students enrolled
$19
$85
78% off
Take This Course
  • Lectures 33
  • Length 2 hours
  • Skill Level All Levels
  • Languages English
  • Includes Lifetime access
    30 day money back guarantee!
    Available on iOS and Android
    Certificate of Completion
Wishlisted Wishlist

How taking a course works

Discover

Find online courses made by experts from around the world.

Learn

Take your courses with you and learn anywhere, anytime.

Master

Learn and practice real-world skills and achieve your goals.

About This Course

Published 12/2014 English

Course Description

Knockout is a JavaScript MVVM (Model View ViewModel) library that helps you create rich, dynamic user interfaces with clean, maintainable code. Moreover, Knockout automatically updates the UI when your data model state changes, ridding you of the need to refresh the page. As a developer, discover how you can use KnockoutJS to architect a complete single page web application from start to finish while maintaining its structure and flexibility!

This course walks you through the process of creating a real-life web application using the MVVM pattern to add functionality to the code as it evolves. If your JavaScript often turns into a giant convoluted mess while building an application with Knockout, this video course will give you an insight on how to organize your code to avoid this.

Starting with an overview of the core concepts behind KnockoutJS to create a real-world application, you'll begin your journey by first learning to build a simplified version of Google Docs. You'll discover the power of data binding and dependency tracking to automatically keep various parts of your application in sync. Next, you’ll learn how you can use debugging techniques to track errors before moving on to creating a spreadsheet to represent more complex data structures. Lastly, you’ll learn how to create a form and then save and load a page using server side functionality.

The final section of the course lets you explore best practices and some additional tools you can use to ensure a maintainable code base.

What are the requirements?

  • A basic understanding of the JavaScript language, HTML, CSS, and object-oriented principles is expected.
  • A clear and practical approach to building a web application with sample code provided to help you every step of the way so you can see not just the final product, but also the evolution of the code base.

What am I going to get from this course?

  • Use declarative data-binding to specify what your code should do in the HTML markup
  • Write class-based JavaScript code to encapsulate functionality similar to object-oriented languages
  • Apply the MVVM pattern to utilize two-way bindings between JavaScript and HTML
  • Use knockout templates to organize and reuse markup
  • Dynamically choose a template based on the type of object
  • Learn how the "this" keyword works in JavaScript and how to use it effectively
  • Utilize computed properties to automatically track dependencies

What is the target audience?

  • This course is aimed at both back-end and front-end web application developers with a basic knowledge of KnockoutJS and an interest in effectively building a single web page application from start to finish.

What you get with this course?

Not for you? No problem.
30 day money back guarantee.

Forever yours.
Lifetime access.

Learn on the go.
Desktop, iOS and Android.

Get rewarded.
Certificate of completion.

Curriculum

Section 1: Exploring KnockoutJS
02:07

Using HTML and JavaScript to manipulate large amounts of data is tricky. KnockoutJS helps encapsulate that complexity into a more manageable form.

02:02

HTML is good at defining layouts but not so great at defining interactions. Using data-binding attributes, you can declare what the markup will be doing while leaving the how up to the JavaScript.

01:34

Manually updating the UI in response to changing data is a tedious and error-prone task. KnockoutJS handles the task of keeping HTML and JavaScript in sync for you.

01:38

Sometimes you have a property (such as a person's full name) that's dependent on other properties (such as first name and last name). KnockoutJS helps you keep track of those dependencies and propagates updates up the chain of dependencies.

02:18

One of the most common and useful features of any framework for creating a single page application is templating. While there are many excellent templating libraries out there, Knockout templates integrate well with KnockoutJS, allowing you to fully utilize all the other features of KnockoutJS.

Section 2: Using KnockoutJS
01:29

Working on a data-centric application on the web can be tricky. KnockoutJShelps you work with data in a more object-oriented manner that is more appropriate when working with data.

02:15

When there are many parts to a system, it gets difficult to keep track of all of them simultaneously. With a smartly architectured KnockoutJS solution, it is possible to keep those components as separated as possible so we can work on them in smaller chunks at a time.

02:43

Most web developers are familiar with the Model View Controller (MVC) pattern. The MVVM pattern serves a similar purpose but is more suitable for two-way data binding. MVC is typically concerned with how to output the HTML, not how to interact back and forth with the DOM.

Section 3: Getting Started with Knockout Docs
03:19

The simplest type of object we'll want to store in Knockout Docs is a basic document. We'll create an object to represent that document and bind it with Knockout.

02:34

We now have one document, but that by itself isn't that useful. With observable arrays, we can have Knockout change the tracking mechanism for the arrays of objects.

02:36

We now have a list of documents that we can display, but we need to be able to select one for editing or display. We can use an observable array to hold the currently selected document and use the with binding to display that document.

04:41

Now that our document has started to gain a little complexity, it makes sense to introduce class-based object-oriented programming into JavaScript. baseJSis a simple library that makes classes clean and easy to work with.

02:13

In server-side languages, you usually have a way to extract out parts of a view as separate files that can be included. Templates in Knockout can serve the same purpose. They can either be brought in using a server-side technology or we can use the KnockoutJS-External-Template-Engine library to bring them in asynchronously.

Section 4: Common Errors and Debugging
01:58

There are a number of common errors that developers new to Knockout encounter. We'll cover some of these common errors and how to resolve them.

02:51

A good library is helpful with debugging. Knockout offers a good amount of help with debugging. Here are some tips and tricks to help with debugging a Knockout application.

01:36

Knockout Context Debugger is a Chrome extension that lets you view the ViewModel of the currently selected DOM element.

03:36

Sometimes we want to know when the value of an observable changed. Subscriptions along with the debugger statement can help us inspect the call stack when a value changes.

Section 5: A More Complex Type: Spreadsheets
02:06

We are now ready to create a new type of document. The spreadsheet type is a more complex type that illustrates a Knockout application better.

02:24

We have a class to represent the data. Now we need a way to display it.

03:19

We have a way to display and edit items, but we don't yet have a way for users to create new ones. We'll need to add some UI elements for item creation.

04:13

Now that we have a working spreadsheet and can create new ones, we need a way for users to add new rows and columns. In this section, we will focus on the ViewModel portion of that functionality.

04:58

Now that the ViewModel portion is done, we need to set up the view to properly implement that functionality.

Section 6: Advanced Techniques
06:39

A common operation that needs to be done is filtering. This is often tricky to do on the client side, but Knockout makes the process simple.

04:18

Another common feature that is needed is autosave. By taking advantage of the dependency tracking in computed properties, we can implement a smart autosave that only triggers when a change is made.

04:48

Sometimes we need to directly modify the UI. Custom bindings allow us to do that without having the logic in the ViewModel or in the view itself.

04:10

Knockout's extensibility means that there are many third-party custom bindings that can be treated as Knockout extensions. The sortable binding is a useful one for drag-and-drop reordering of items.

Section 7: Working With Forms: Creating Surveys
03:46

We will now create our final type, a survey. As with our other types, we will create a class to house the logic and data for our survey template.

03:34

We now have a survey class with one question type. Now we add another question type for checkboxes.

03:15

Now that we have a checkbox question with multiple options, we can add question types for radio buttons and select lists.

04:41

We can now edit our survey questions, but we still need a way to preview them. We can add a toggle to switch between the edit and preview mode.

Section 8: Saving and Loading Data
07:26

A ViewModel has many properties that may not be appropriate or necessary to be saved. We can use the toJSON function to determine what gets serialized.

05:58

In addition to determining how to serialize data, we also need to determine how to populate the data retrieved from the server. We can create a complementary function called fromJSON to determine how to populate our classes from the server data.

04:04

We have now created a full single page application using KnockoutJS. There are many more advanced usage scenarios to be investigated further.

Students Who Viewed This Course Also Viewed

  • Loading
  • Loading
  • Loading

Instructor Biography

Packt Publishing, Tech Knowledge in Motion

Over the past ten years Packt Publishing has developed an extensive catalogue of over 2000 books, e-books and video courses aimed at keeping IT professionals ahead of the technology curve. From new takes on established technologies through to the latest guides on emerging platforms, topics and trends – Packt's focus has always been on giving our customers the working knowledge they need to get the job done. Our Udemy courses continue this tradition, bringing you comprehensive yet concise video courses straight from the experts.

Ready to start learning?
Take This Course