Explorar o código

pastojs: createCallback: store events in $events to create unique method pointers, issue #38845

git-svn-id: trunk@49331 -
(cherry picked from commit f5d138eb087a46053efb39c6b3e417ef30cfe551)
Mattias Gaertner %!s(int64=4) %!d(string=hai) anos
pai
achega
f372945211
Modificáronse 1 ficheiros con 24 adicións e 15 borrados
  1. 24 15
      utils/pas2js/dist/rtl.js

+ 24 - 15
utils/pas2js/dist/rtl.js

@@ -229,7 +229,10 @@ var rtl = {
   createCallback: function(scope, fn){
   createCallback: function(scope, fn){
     var cb;
     var cb;
     if (typeof(fn)==='string'){
     if (typeof(fn)==='string'){
-      cb = function(){
+      if (!scope.$events) scope.$events = {};
+      cb = scope.$events[fn];
+      if (cb) return cb;
+      scope.$events[fn] = cb = function(){
         return scope[fn].apply(scope,arguments);
         return scope[fn].apply(scope,arguments);
       };
       };
     } else {
     } else {
@@ -243,32 +246,38 @@ var rtl = {
   },
   },
 
 
   createSafeCallback: function(scope, fn){
   createSafeCallback: function(scope, fn){
-    var cb = function(){
-      try{
-        if (typeof(fn)==='string'){
+    var cb;
+    if (typeof(fn)==='string'){
+      if (!scope.$events) scope.$events = {};
+      cb = scope.$events[fn];
+      if (cb) return cb;
+      scope.$events[fn] = cb = function(){
+        try{
           return scope[fn].apply(scope,arguments);
           return scope[fn].apply(scope,arguments);
-        } else {
+        } catch (err) {
+          if (!rtl.handleUncaughtException(err)) throw err;
+        }
+      };
+    } else {
+      cb = function(){
+        try{
           return fn.apply(scope,arguments);
           return fn.apply(scope,arguments);
-        };
-      } catch (err) {
-        if (!rtl.handleUncaughtException(err)) throw err;
-      }
+        } catch (err) {
+          if (!rtl.handleUncaughtException(err)) throw err;
+        }
+      };
     };
     };
     cb.scope = scope;
     cb.scope = scope;
     cb.fn = fn;
     cb.fn = fn;
     return cb;
     return cb;
   },
   },
 
 
-  cloneCallback: function(cb){
-    return rtl.createCallback(cb.scope,cb.fn);
-  },
-
   eqCallback: function(a,b){
   eqCallback: function(a,b){
     // can be a function or a function wrapper
     // can be a function or a function wrapper
-    if (a==b){
+    if (a===b){
       return true;
       return true;
     } else {
     } else {
-      return (a!=null) && (b!=null) && (a.fn) && (a.scope===b.scope) && (a.fn==b.fn);
+      return (a!=null) && (b!=null) && (a.fn) && (a.scope===b.scope) && (a.fn===b.fn);
     }
     }
   },
   },