Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The spec allows you to define <em>internal</em> modules across multiple files (in essence, internal modules refer to the javascript module pattern). <em>External</em> modules, such as AMD or CommonJS modules, work on the idea that each file is the actual "module of code", and the namespacing/naming within it is irrelevant since the module will be loaded into its own new object anyway.</p> <p>You could write the following code to load the Contact.ts module inside of the ContactView.ts module:</p> <pre><code>// file ContactView.ts import mod = module("./Contact"); export module Contacts { export class ContactView { model: mod.Contacts.Contact; // &lt;--- will be recognized } } </code></pre> <p>And that should work well enough, but if you wanted to have access to the contents of both modules in another area (to for example make a new Contact model yourself), you would have to essentially import both of them:</p> <pre><code>import c = module("./Contact"); import cv = module("./ContactView"); </code></pre> <p>Which I think is fine enough, because you're clearly stating your dependencies. The downside is that they wont share a common parent object, so having them both be in a "Contact" module-pattern probably isn't of great use.</p> <p>Another option is to export "Contact" along with "ContactView", as follows (granted this code is kind of silly because you're already doing exactly that via the model property of ContactView, but never the less...):</p> <pre><code>export module Contacts { export class ContactView { model: mod.Contacts.Contact; constructor() { this.model = new mod.Contacts.Contact(); } } export var Contact = mod.Contacts.Contact; } </code></pre> <p>So you'd be able to access it after having loaded ContactView.</p> <p>EDIT: By the way, you aren't limited to only exporting modules via "export module Name { ... }", you can export anything as the file itself is the module. So you could have a file which just has "export function foo() { ... }" without any module-pattern code wrapping it.</p> <p>EDIT2: It looks like AMD might have functionality for loading multiple dependencies and constructing "modules" from those, but I have no idea how that would work in TS, here's a link that goes over that: <a href="http://www.adobe.com/devnet/html5/articles/javascript-architecture-requirejs-dependency-management.html" rel="noreferrer">http://www.adobe.com/devnet/html5/articles/javascript-architecture-requirejs-dependency-management.html</a> (Constructor modules).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload