title: RequireJS: How to pass updated data between modules
body: <p>This is the first time I look into requirejs. I've been doing that by porting an old project of mine. So far it's coming along well. Until now.</p>
  
  <p>What I've always done is keeping a site settings object containing system settings such as window height, window width, document height, scrolltop etc. In there I updated those values with resize and scroll events. Those were always global variables that I could access.</p>
  
  <p><strong>For example (using jQuery)</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var mySettingsObject = {};
  mySettingsObject.Init = function() {
    this.winWidth = $(window).width();
  
    $(window).resize(function(e) {
      mySettingsObject.winWidth = $(window).width();
    });
  };
  
  $(document).ready(function) {
    mySettingsObject.Init();
  });</code></pre>
  </div>
  </div>
  </p>
  
  <p>Now I can access that variable by calling mySettingsObject.winWidth at any time from any function and it will always be up to date.</p>
  
  <p>What I am trying to understand is how I can have the same behaviour using module dependency in requirejs?</p>
  
  <p><strong>These are my two example modules</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>define('system', function() {
    // Window settings 
    var winWidth = $(window).width();
    $(window).resize(function(e) {
      winWidth = $(window).width();
    }
  
    return {
      winWidth: winWidth
    };
    
  });
  
  
  // (is run on dom load)
  define('myModule', ['system'], function(system) {
    $(window).on('resize', function() {
      if (system.winHeight === xyz) {
        // do something
      }
    });
  });</code></pre>
  </div>
  </div>
  </p>
  
  <p>The system.winHeight works as expected and gives me the window height as it was on dom load. Now, if I resize the browser, how can I have that variable update itself within <em>myModule</em>, i.e. how can i make the two modules communicate.</p>