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

Widgets


Widgets in Durandal are similar to Knockout components, in that they are viewmodel/view pairs that are instantiated from the DOM. Components use a custom element while widgets use a custom binding. There is definitely some overlap between them, but Durandal's widget system came before Knockout's component system. Widgets also have a killer feature over components; their views can have replaceable sections that can be overridden. This feature is commonly known as transclusion—the inclusion of one document inside another.

It's difficult to talk about the widget API without using an example. When we looked at components, we made a contact list component; so let's see what it would look like doing the same thing with a widget. It may not be very reusable, making it an odd choice for a widget; but it will cover the whole process.

Creating a new widget

Durandal expects widgets to be located in a directory named widgets, at the root of your app, which, in our case, would be under client/app...