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

Import notification order

Expand Messages
  • mathias.brodala
    First I d like to thank you for this framework, it seems to provide features JavaScript is still missing for proper code management. ... // index.js // Enforce
    Message 1 of 3 , Dec 29, 2010
    View Source
    • 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:

      ---8<---
      // 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
      Namespace("my.test");

      Import("my.test.MyClass");
      Import("my.test.MyOtherClass");

      // my/test/MyClass.js
      Namespace("my.test");

      Import("my.test.MyOtherClass");

      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
      Namespace("my.test");

      my.test.MyOtherClass = function() {

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

      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:

      ---8<---
      // index.js
      Import("my.test.*");

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

      var myother = new MyOtherClass();
      var my = new MyClass();
      });
      --->8---

      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.
    • mathias.brodala
      First I d like to thank you for this framework, it seems to provide features JavaScript is still missing for proper code management. ... // index.js // Enforce
      Message 2 of 3 , Dec 29, 2010
      View Source
      • 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:

        ---8<---
        // 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
        Namespace("my.test");

        Import("my.test.MyClass");
        Import("my.test.MyOtherClass");

        // my/test/MyClass.js
        Namespace("my.test");

        Import("my.test.MyOtherClass");

        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
        Namespace("my.test");

        my.test.MyOtherClass = function() {

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

        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:

        ---8<---
        // index.js
        Import("my.test.*");

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

        var myother = new MyOtherClass();
        var my = new MyClass();
        });
        --->8---

        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.
      • iskitzdev
        Hi Mathias, You re welcome. Thanks for the suggestion and sample code. I tested what you provided and confirmed the problem in Firefox. I spent some time in
        Message 3 of 3 , Jan 4, 2011
        View Source
        • 0 Attachment
          Hi Mathias,

          You're welcome.

          Thanks for the suggestion and sample code. I tested what you provided and confirmed the problem in Firefox.

          I spent some time in past releases working on the import notification order so this may be a bug or an oversight. Testing with your sample code showed that listening for "my.test" works in WebKit browsers, but not Firefox. IE is still to be tested.

          A full-blown release may be a bit more than I can get done right now, but if I find the root cause I'll send you a patch.


          -Michael


          --- In ajile@yahoogroups.com, "mathias.brodala" <mathias.brodala@...> wrote:
          >
          > 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:
          >
          > ---8<---
          > // 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
          > Namespace("my.test");
          >
          > Import("my.test.MyClass");
          > Import("my.test.MyOtherClass");
          >
          > // my/test/MyClass.js
          > Namespace("my.test");
          >
          > Import("my.test.MyOtherClass");
          >
          > 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
          > Namespace("my.test");
          >
          > my.test.MyOtherClass = function() {
          >
          > this.getHello = function() { return "Hello"; };
          > };
          > --->8---
          >
          > 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:
          >
          > ---8<---
          > // index.js
          > Import("my.test.*");
          >
          > Ajile.AddImportListener("my.test", function() {
          >
          > var myother = new MyOtherClass();
          > var my = new MyClass();
          > });
          > --->8---
          >
          > 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.
          >
        Your message has been successfully submitted and would be delivered to recipients shortly.