1
0
Pārlūkot izejas kodu

Merge branch 'master' of github.com:amber-smalltalk/amber

Nicolas Petton 12 gadi atpakaļ
vecāks
revīzija
c86904ccff
1 mainītis faili ar 24 papildinājumiem un 5 dzēšanām
  1. 24 5
      js/init.js

+ 24 - 5
js/init.js

@@ -1,7 +1,26 @@
-smalltalk.initialize();
+(function () {
+    var inBrowser = typeof amber !== "undefined" && typeof amber.load === "function";
+    function init() {
+        smalltalk.initialize();
 
-/* Similar to jQuery(document).ready() */
+        /* Similar to jQuery(document).ready() */
 
-if(this.amber && this.amber.smalltalkReady) {
-	this.amber.smalltalkReady();
-}
+        if (inBrowser && amber.smalltalkReady) {
+            amber.smalltalkReady();
+        }
+    }
+
+    if (inBrowser) {
+        // init is lengthy process done in JavaScript.
+        // setTimeout here postpones it, so DOM ready
+        // event can occur sooner, thus load process
+        // may appear optically faster.
+        setTimeout(init, 0);
+    } else {
+        // In certain configurations, setTimeout is not feasible.
+        // It is mainly for `amberc`-produced concatenated
+        // node.js programs. There, the actual "main" appears
+        // immediately after init, so it must happens synchronously.
+        init();
+    }
+})();