1
0
Prechádzať zdrojové kódy

kernel: selector.selectorPairs => dnu.jsSelectors.

Herby Vojčík 6 rokov pred
rodič
commit
8a849058b9
2 zmenil súbory, kde vykonal 19 pridanie a 21 odobranie
  1. 2 7
      support/kernel-fundamentals.js
  2. 17 14
      support/kernel-runtime.js

+ 2 - 7
support/kernel-fundamentals.js

@@ -95,20 +95,15 @@ define(function () {
         this.Object = SmalltalkObject;
     }
 
-    SelectorsBrik.deps = ["selectorConversion"];
     function SelectorsBrik (brikz, st) {
         var selectorSet = Object.create(null);
         var selectors = this.selectors = [];
-        var selectorPairs = this.selectorPairs = [];
 
         this.registerSelector = function (stSelector) {
             if (selectorSet[stSelector]) return null;
-            var jsSelector = st.st2js(stSelector);
             selectorSet[stSelector] = true;
             selectors.push(stSelector);
-            var pair = {st: stSelector, js: jsSelector};
-            selectorPairs.push(pair);
-            return pair;
+            return {st: stSelector};
         };
 
         st.allSelectors = function () {
@@ -298,7 +293,7 @@ define(function () {
 
     function SelectorConversionBrik (brikz, st) {
         /* Convert a Smalltalk selector into a JS selector */
-        st.st2js = function (string) {
+        st.st2js = this.st2js = function (string) {
             return '_' + string
                     .replace(/:/g, '_')
                     .replace(/[\&]/g, '_and')

+ 17 - 14
support/kernel-runtime.js

@@ -21,24 +21,28 @@ define(function () {
         installJSMethod(klass.fn.prototype, method.jsSelector, method.fn);
     }
 
-    DNUBrik.deps = ["selectors", "smalltalkGlobals", "classes"];
+    DNUBrik.deps = ["selectors", "selectorConversion", "smalltalkGlobals", "classes"];
     function DNUBrik (brikz, st) {
-        var selectorPairs = brikz.selectors.selectorPairs;
+        var selectors = brikz.selectors.selectors;
         var globals = brikz.smalltalkGlobals.globals;
         var nilAsClass = brikz.classes.nilAsClass;
+        var st2js = brikz.selectorConversion.st2js;
+
+        var jsSelectors = this.jsSelectors = [];
 
         /* Method not implemented handlers */
 
-        function makeDnuHandler (pair, targetClasses) {
-            var jsSelector = pair.js;
-            var fn = createHandler(pair.st);
+        function installNewSelector(selector, targetClasses) {
+            var jsSelector = st2js(selector);
+            jsSelectors.push(jsSelector);
+            var fn = createHandler(selector);
             installJSMethod(nilAsClass.fn.prototype, jsSelector, fn);
             targetClasses.forEach(function (target) {
                 installJSMethod(target.fn.prototype, jsSelector, fn);
             });
         }
 
-        this.makeDnuHandler = makeDnuHandler;
+        this.installNewSelector = installNewSelector;
 
         /* Dnu handler method */
 
@@ -50,14 +54,14 @@ define(function () {
             };
         }
 
-        selectorPairs.forEach(function (pair) {
-            makeDnuHandler(pair, []);
+        selectors.forEach(function (selector) {
+            installNewSelector(selector, []);
         });
     }
 
-    RuntimeClassesBrik.deps = ["event", "selectors", "dnu", "behaviors", "classes"];
+    RuntimeClassesBrik.deps = ["event", "dnu", "behaviors", "classes"];
     function RuntimeClassesBrik (brikz, st) {
-        var selectorPairs = brikz.selectors.selectorPairs;
+        var jsSelectors = brikz.dnu.jsSelectors;
         var traitsOrClasses = brikz.behaviors.traitsOrClasses;
         var wireKlass = brikz.classes.wireKlass;
         var emit = brikz.event.emit;
@@ -117,8 +121,7 @@ define(function () {
         function copySuperclass (klass) {
             var myproto = klass.fn.prototype,
                 superproto = klass.superclass.fn.prototype;
-            selectorPairs.forEach(function (selectorPair) {
-                var jsSelector = selectorPair.js;
+            jsSelectors.forEach(function (jsSelector) {
                 installJSMethod(myproto, jsSelector, superproto[jsSelector]);
             });
         }
@@ -162,7 +165,7 @@ define(function () {
 
     RuntimeMethodsBrik.deps = ["event", "dnu", "runtimeClasses"];
     function RuntimeMethodsBrik (brikz, st) {
-        var makeDnuHandler = brikz.dnu.makeDnuHandler;
+        var installNewSelector = brikz.dnu.installNewSelector;
         var detachedRootClasses = brikz.runtimeClasses.detachedRootClasses;
         var emit = brikz.event.emit;
 
@@ -174,7 +177,7 @@ define(function () {
         emit.selectorsAdded = function (newSelectors) {
             var targetClasses = detachedRootClasses();
             newSelectors.forEach(function (pair) {
-                makeDnuHandler(pair, targetClasses);
+                installNewSelector(pair.st, targetClasses);
             });
         };