Browse Source

kernel: setTraitComposition implemented

Herbert Vojčík 7 years ago
parent
commit
935403837b
1 changed files with 14 additions and 2 deletions
  1. 14 2
      support/kernel-fundamentals.js

+ 14 - 2
support/kernel-fundamentals.js

@@ -351,8 +351,20 @@ define(['./compatibility'], function () {
             // This is handled by #removeCompiledMethod
         }
 
-        function applyTraitTransformation(traitTransformation, obj) {
-            // TODO not implemented yet, noop atm
+        function applyTraitTransformation (traitTransformation, obj) {
+            var traitMethods = traitTransformation.trait.methods;
+            Object.keys(traitMethods).forEach(function (selector) {
+                obj[selector] = traitMethods[selector];
+            });
+            var traitAliases = traitTransformation.aliases || {};
+            Object.keys(traitAliases).forEach(function (aliasSelector) {
+                var aliasedMethod = traitMethods[traitAliases[aliasSelector]];
+                if (aliasedMethod) obj[aliasSelector] = aliasedMethod;
+            });
+            var traitExclusions = traitExclusions || [];
+            traitExclusions.forEach(function (selector) {
+                delete obj[selector];
+            });
             return obj;
         }