The Models module

As we have done with the view-model, we are going to convert each model into a component and we are going to wrap it inside a module called Models, the following steps:

  1. Open the models/product.js file.
  2. Define our top-level module, Shop, and initialize it:
    var Shop;
    Shop = Shop || {};
  3. Then create the Models namespace. It will be an object or the value it has before, in case it exists:
    Shop.Models = Shop.Models || {};
  4. Define the product model with its dependencies. Remember, the first value is the product itself. This allows us to extend the model in case we use many files to define it. So, we define the product model as follows:
    Shop.Models.Product = (function(){
    })()
  5. Pass the dependencies. This time you just need to use the Knockout ...

Get KnockoutJS Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.