Converting a normal module into an AMD module
To convert a normal module, we will perform the following steps. Always apply the same steps for all our modules. We need to wrap them into the define
function, list dependencies, and return the module we returned in our old one.
Open the
viewmodel.js
file.Create the
define
function:define([],function(){});
Add all dependencies:
define([ 'knockout', 'models/Product', 'models/Customer', 'models/CartProduct', 'services/ProductService', 'services/CartProductService', 'resources/ProductResource', 'resources/OrderResource' ],function (ko, Product, Customer, ProductService, CartProductService, ProductResource, OrderResource) { });
Export the module into the
define
function:define([],function(){ var debug = ko.observable(false); var showDebug = function () { debug(true); } ... var activate = function () { ProductResource.all() .done(allCallbackSuccess.bind(this)); }; return { debug: debug, showDebug:showDebug...