Book Image

Knockout.JS Essentials

Book Image

Knockout.JS Essentials

Overview of this book

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

The shell view-model


Shell is the entry point module. It is the module that wraps the other modules. It is loaded just once and has the DOM elements that persist all the time.

To define a view-model, define a simple JavaScript object using the AMD pattern, as done in the following steps:

  1. Define dependencies, that is, the router and the Durandal app:

    define(['plugins/router', 'durandal/app'], function (router, app) {
      return {
        //We complete this in next points
      };
    });
  2. Expose the router method. The router method will give us an object that allows us to show the navigation bar easily.

    return {
      router: router
    };
  3. Expose the search method. This is an optional method. It's part of the starter kit application. It manages the global search.

    return {
      router: router,
      search: function() {
        //easy way to show a message box in Durandal
        app.showMessage('Search not yet implemented...');
      },
    };
  4. Expose the activate method. This is an important method in Durandal view-models. The activate method...