Loading ...
Sorry, an error occurred while loading the content.

294Import notification order

Expand Messages
  • mathias.brodala
    Dec 29, 2010
    • 0 Attachment
      First I'd like to thank you for this framework, it seems to provide features JavaScript is still missing for proper code management.

      However, I'd like to suggest a tweak for the import notification order. ATM the first notification when importing something is always the base package. An Example:

      // index.js
      // Enforce directory based hierarchy
      Import("my.test.MyClass", null, "/");

      Ajile.AddImportListener(function(moduleName) {

      if (moduleName.indexOf("my.test") > -1) {

      alert("Imported: " + moduleName);

      // my/test.js


      // my/test/MyClass.js


      my.test.MyClass = function() {

      // XXX: MyOtherClass is not bound to be defined yet
      var other = new MyOtherClass();

      this.getGreeting = function() {

      return other.getHello() + " World";

      // my/test/MyOtherClass.js

      my.test.MyOtherClass = function() {

      this.getHello = function() { return "Hello"; };

      This will notify about import in the following order:

      1) my.test
      2) my.test.MyClass
      (Randomy inserted the import of my.test.MyOtherClass)

      The import notification about "my.test" is not really useful as first notification. You cannot use anything within that package at that time since you cannot be sure that everything within has been loaded yet.

      My proposal: Defer the notification of a module import until all of its imports have been completed. This allows for the following:

      // index.js

      Ajile.AddImportListener("my.test", function() {

      var myother = new MyOtherClass();
      var my = new MyClass();

      Here it is ensured that "MyOtherClass" and "MyClass" are defined since the import notification for "my.test" does fire at the end of all imports for the "my.test" package.
    • Show all 3 messages in this topic