Reference an application-level module in a widget

To reference an application-level module in a widget, you must list the module as a dependency using the ccResourceLoader library.

For example, the following code creates a dependency on the demo.shared.viewmodels module:

define(
          //-------------------------------------------------------------------
          // DEPENDENCIES
          //-------------------------------------------------------------------
          ['jquery', 'knockout', 'ccLogger',
            'ccResourceLoader!global/demo.shared.viewmodels'],
          //-------------------------------------------------------------------
          // Module definition
          //-------------------------------------------------------------------
          function ($, ko, ccLogger, sharedViewModel) {     'use strict';
            return {
              onLoad : function(widget) {
                widget.firstName = sharedViewModel.viewModel().firstName;
                widget.surname = sharedViewModel.viewModel().surname;
                widget.doMessage = sharedViewModel.doMessage;
            }
       };
   }
 );

Note that you cannot reference an application-level module from another application-level module. Application-level modules are loaded in parallel whenever a page is loaded, meaning that the order in which they are loaded is not guaranteed. This means that you cannot have a dependency form one application-level module to another.