Browse Source

kernel: Extract setLocalMethods.

Herby Vojčík 4 years ago
parent
commit
6f84d7afc0
2 changed files with 17 additions and 9 deletions
  1. 14 0
      lang/base/kernel-fundamentals.js
  2. 3 9
      lang/base/kernel-language.js

+ 14 - 0
lang/base/kernel-fundamentals.js

@@ -174,6 +174,20 @@ define(['./junk-drawer'], function ($goodies) {
                 traitOrBehavior.methods = Object.create(null);
             };
 
+            function setLocalMethods (traitOrBehavior, newLocalMethods) {
+                var oldLocalMethods = traitOrBehavior.localMethods;
+                traitOrBehavior.localMethods = newLocalMethods;
+                var selector;
+                for (selector in newLocalMethods) {
+                    updateMethod(selector, traitOrBehavior);
+                }
+                for (selector in oldLocalMethods) {
+                    updateMethod(selector, traitOrBehavior);
+                }
+            }
+
+            this.setLocalMethods = setLocalMethods;
+
             declareEvent("methodReplaced");
 
             function updateMethod (selector, traitOrBehavior) {

+ 3 - 9
lang/base/kernel-language.js

@@ -12,6 +12,7 @@ define(['./junk-drawer'], function ($goodies) {
     MethodCompositionBrik.deps = ["methods"];
 
     function MethodCompositionBrik (brikz, st) {
+        var setLocalMethods = brikz.methods.setLocalMethods;
         var updateMethod = brikz.methods.updateMethod;
 
         function aliased (selector, method) {
@@ -59,15 +60,8 @@ define(['./junk-drawer'], function ($goodies) {
 
         st.setTraitComposition = function (traitComposition, traitOrBehavior) {
             var oldLocalMethods = traitOrBehavior.localMethods,
-                newLocalMethods = Object.create(buildCompositionChain(traitComposition));
-            traitOrBehavior.localMethods = extend(newLocalMethods, oldLocalMethods);
-            var selector;
-            for (selector in newLocalMethods) {
-                updateMethod(selector, traitOrBehavior);
-            }
-            for (selector in oldLocalMethods) {
-                updateMethod(selector, traitOrBehavior);
-            }
+                newLocalMethodsTemplate = Object.create(buildCompositionChain(traitComposition));
+            setLocalMethods(traitOrBehavior, extend(newLocalMethodsTemplate, oldLocalMethods));
             (traitOrBehavior.traitComposition || []).forEach(function (each) {
                 removeElement(each.trait.traitUsers, traitOrBehavior);
             });