Explorar el Código

loader: refactorings

Less `window` and `smalltalk` global usage.
Using global `amber` as a communication channel for load/init.
Moved toggleAmberIDE into smalltalk and calling it.
Herbert Vojčík hace 11 años
padre
commit
d3bd790e13
Se han modificado 8 ficheros con 95 adiciones y 47 borrados
  1. 20 0
      js/IDE.deploy.js
  2. 25 0
      js/IDE.js
  3. 5 5
      js/Kernel-Objects.deploy.js
  4. 6 6
      js/Kernel-Objects.js
  5. 16 28
      js/amber.js
  6. 2 2
      js/init.js
  7. 15 0
      st/IDE.st
  8. 6 6
      st/Kernel-Objects.st

+ 20 - 0
js/IDE.deploy.js

@@ -1145,6 +1145,26 @@ return self}, function($ctx1) {$ctx1.fill(self,"new",{}, smalltalk.TabManager.kl
 messageSends: ["shouldNotImplement"]}),
 smalltalk.TabManager.klass);
 
+smalltalk.addMethod(
+"_toggleAmberIDE",
+smalltalk.method({
+selector: "toggleAmberIDE",
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+		if ($('#amber').length == 0) {
+			smalltalk.Browser._open();
+		} else if ($('#amber').is(':visible')) {
+			smalltalk.TabManager._current()._close();
+		} else {
+			smalltalk.TabManager._current()._open();
+		}
+		return false;
+;
+return self}, function($ctx1) {$ctx1.fill(self,"toggleAmberIDE",{}, smalltalk.TabManager.klass)})},
+messageSends: []}),
+smalltalk.TabManager.klass);
+
 
 smalltalk.addClass('TabWidget', smalltalk.Widget, ['div'], 'IDE');
 smalltalk.addMethod(

+ 25 - 0
js/IDE.js

@@ -1490,6 +1490,31 @@ referencedClasses: []
 }),
 smalltalk.TabManager.klass);
 
+smalltalk.addMethod(
+"_toggleAmberIDE",
+smalltalk.method({
+selector: "toggleAmberIDE",
+category: 'actions',
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+		if ($('#amber').length == 0) {
+			smalltalk.Browser._open();
+		} else if ($('#amber').is(':visible')) {
+			smalltalk.TabManager._current()._close();
+		} else {
+			smalltalk.TabManager._current()._open();
+		}
+		return false;
+;
+return self}, function($ctx1) {$ctx1.fill(self,"toggleAmberIDE",{}, smalltalk.TabManager.klass)})},
+args: [],
+source: "toggleAmberIDE\x0a<\x0a\x09\x09if ($('#amber').length == 0) {\x0a\x09\x09\x09smalltalk.Browser._open();\x0a\x09\x09} else if ($('#amber').is(':visible')) {\x0a\x09\x09\x09smalltalk.TabManager._current()._close();\x0a\x09\x09} else {\x0a\x09\x09\x09smalltalk.TabManager._current()._open();\x0a\x09\x09}\x0a\x09\x09return false;\x0a>",
+messageSends: [],
+referencedClasses: []
+}),
+smalltalk.TabManager.klass);
+
 
 smalltalk.addClass('TabWidget', smalltalk.Widget, ['div'], 'IDE');
 smalltalk.addMethod(

+ 5 - 5
js/Kernel-Objects.deploy.js

@@ -2574,11 +2574,11 @@ selector: "commitPathsFromLoader",
 fn: function (){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
-    var cp = smalltalk['@@commitPath'];
-    if (!cp) return;
-    if (cp.js) self._defaultCommitPathJs_(cp.js);
-    if (cp.st) self._defaultCommitPathSt_(cp.st);
-    ;
+	var cp = typeof amber !== 'undefined' && amber.commitPath;
+	if (!cp) return;
+	if (cp.js) self._defaultCommitPathJs_(cp.js);
+	if (cp.st) self._defaultCommitPathSt_(cp.st);
+;
 return self}, function($ctx1) {$ctx1.fill(self,"commitPathsFromLoader",{}, smalltalk.Package.klass)})},
 messageSends: []}),
 smalltalk.Package.klass);

+ 6 - 6
js/Kernel-Objects.js

@@ -3561,14 +3561,14 @@ category: 'commit paths',
 fn: function (){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
-    var cp = smalltalk['@@commitPath'];
-    if (!cp) return;
-    if (cp.js) self._defaultCommitPathJs_(cp.js);
-    if (cp.st) self._defaultCommitPathSt_(cp.st);
-    ;
+	var cp = typeof amber !== 'undefined' && amber.commitPath;
+	if (!cp) return;
+	if (cp.js) self._defaultCommitPathJs_(cp.js);
+	if (cp.st) self._defaultCommitPathSt_(cp.st);
+;
 return self}, function($ctx1) {$ctx1.fill(self,"commitPathsFromLoader",{}, smalltalk.Package.klass)})},
 args: [],
-source: "commitPathsFromLoader\x0a    <\x0a    var cp = smalltalk['@@commitPath'];\x0a    if (!cp) return;\x0a    if (cp.js) self._defaultCommitPathJs_(cp.js);\x0a    if (cp.st) self._defaultCommitPathSt_(cp.st);\x0a    >",
+source: "commitPathsFromLoader\x0a<\x0a\x09var cp = typeof amber !== 'undefined' && amber.commitPath;\x0a\x09if (!cp) return;\x0a\x09if (cp.js) self._defaultCommitPathJs_(cp.js);\x0a\x09if (cp.st) self._defaultCommitPathSt_(cp.st);\x0a>",
 messageSends: [],
 referencedClasses: []
 }),

+ 16 - 28
js/amber.js

@@ -21,17 +21,6 @@ amber = (function() {
 	var loadJS;
 	var nocache = '';
 
-	that.toggleIDE = function() {
-		if ($('#amber').length == 0) {
-			smalltalk.Browser._open();
-		} else if ($('#amber').is(':visible')) {
-			smalltalk.TabManager._current()._close();
-		} else {
-			smalltalk.TabManager._current()._open();
-		}
-		return false;
-	};
-
 	that.load = function(obj) {
 		spec = obj || {};
 
@@ -104,14 +93,13 @@ amber = (function() {
 		}
 
 		var additionalFiles = spec.packages || spec.files;
-		var commitPathForInit = null;
 		if (additionalFiles) {
-			commitPathForInit = loadPackages(additionalFiles, spec.prefix, spec.packageHome);
+			that.commitPath = loadPackages(additionalFiles, spec.prefix, spec.packageHome);
 		}
 
 		// Be sure to setup & initialize smalltalk classes
 		addJSToLoad('js/init.js');
-		initializeSmalltalk(commitPathForInit);
+		initializeSmalltalk();
 	};
 
 	function loadPackages(names, prefix, urlHome){
@@ -208,19 +196,15 @@ amber = (function() {
 	}
 
 	// This will be called after JS files have been loaded
-	function initializeSmalltalk(commitPath) {
-		window.smalltalkReady = function() {
-			if (commitPath) {
-				smalltalk['@@commitPath'] = commitPath;
-				smalltalk.Package._commitPathsFromLoader();
-			}
-			if (spec.ready) {
-				spec.ready();
-			}
-			evaluateSmalltalkScripts();
-		};
-
-		loadAllJS();
+	function initializeSmalltalk() {
+		that.smalltalkReady = function() {
+            if (spec.ready) {
+                spec.ready();
+            }
+            evaluateSmalltalkScripts();
+        };
+
+        loadAllJS();
 	}
 
 	/*
@@ -308,4 +292,8 @@ amber = (function() {
 })();
 
 window.loadAmber = amber.load;
-window.toggleAmberIDE = amber.toggleIDE;
+
+// Backward compatibility
+function toggleAmberIDE () {
+    return smalltalk.TabManager._toggleAmberIDE();
+}

+ 2 - 2
js/init.js

@@ -2,6 +2,6 @@ smalltalk.initialize();
 
 /* Similar to jQuery(document).ready() */
 
-if(this.smalltalkReady) {
-	this.smalltalkReady();
+if(this.amber && this.amber.smalltalkReady) {
+	this.amber.smalltalkReady();
 }

+ 15 - 0
st/IDE.st

@@ -519,6 +519,21 @@ update
 
 TabManager class instanceVariableNames: 'current'!
 
+!TabManager class methodsFor: 'actions'!
+
+toggleAmberIDE
+<
+		if ($('#amber').length == 0) {
+			smalltalk.Browser._open();
+		} else if ($('#amber').is(':visible')) {
+			smalltalk.TabManager._current()._close();
+		} else {
+			smalltalk.TabManager._current()._open();
+		}
+		return false;
+>
+! !
+
 !TabManager class methodsFor: 'instance creation'!
 
 current

+ 6 - 6
st/Kernel-Objects.st

@@ -1199,12 +1199,12 @@ named: aPackageName ifAbsent: aBlock
 !Package class methodsFor: 'commit paths'!
 
 commitPathsFromLoader
-    <
-    var cp = smalltalk['@@commitPath'];
-    if (!!cp) return;
-    if (cp.js) self._defaultCommitPathJs_(cp.js);
-    if (cp.st) self._defaultCommitPathSt_(cp.st);
-    >
+<
+	var cp = typeof amber !!== 'undefined' && amber.commitPath;
+	if (!!cp) return;
+	if (cp.js) self._defaultCommitPathJs_(cp.js);
+	if (cp.st) self._defaultCommitPathSt_(cp.st);
+>
 !
 
 defaultCommitPathJs