The Resources module

In terms of code, building a module that contains a model and building one that contains a resource is not so different. The module pattern applied is the same. Nevertheless, you don't need to create instances of the resources. To apply CRUD operations to the models, you just need an object that handles this responsibility. Therefore, the resources will be singletons, as done in the following steps:

  1. Open the resources/ProductResource.js file.
  2. Create the top hierarchy module:
    var Shop;
    Shop = Shop || {};
  3. Create the Resources namespace:
    Shop.Resources = Shop.Resources || {};
  4. Define ProductResource using the module pattern:
    Shop.Resources.ProductResource = (function(){
    })()
  5. Set the dependencies. In this case, jQuery is the dependency ...

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.