X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/25ef3491bd9ae007ff1fc2b0d7943e6eaaccf775..2e847cf21b8ab9d15fa167b315ca5b2fa92638fc:/src/util/core/Observable.js diff --git a/src/util/core/Observable.js b/src/util/core/Observable.js index c1f5452f..dc18313a 100644 --- a/src/util/core/Observable.js +++ b/src/util/core/Observable.js @@ -1,6 +1,6 @@ /*! - * Ext JS Library 3.0.3 - * Copyright(c) 2006-2009 Ext JS, LLC + * Ext JS Library 3.1.1 + * Copyright(c) 2006-2010 Ext JS, LLC * licensing@extjs.com * http://www.extjs.com/license */ @@ -286,9 +286,11 @@ this.addEvents('storeloaded', 'storecleared'); var me = this; me.events = me.events || {}; if (Ext.isString(o)) { - EACH(arguments, function(a) { - me.events[a] = me.events[a] || TRUE; - }); + var a = arguments, + i = a.length; + while(i--) { + me.events[a[i]] = me.events[a[i]] || TRUE; + } } else { Ext.applyIf(me.events, o); } @@ -369,26 +371,28 @@ function createTargeted(h, o, scope){ }; }; -function createBuffered(h, o, scope){ - var task = new EXTUTIL.DelayedTask(); +function createBuffered(h, o, l, scope){ + l.task = new EXTUTIL.DelayedTask(); return function(){ - task.delay(o.buffer, h, scope, TOARRAY(arguments)); + l.task.delay(o.buffer, h, scope, TOARRAY(arguments)); }; -} +}; function createSingle(h, e, fn, scope){ return function(){ e.removeListener(fn, scope); return h.apply(scope, arguments); }; -} +}; -function createDelayed(h, o, scope){ +function createDelayed(h, o, l, scope){ return function(){ - var args = TOARRAY(arguments); - (function(){ - h.apply(scope, args); - }).defer(o.delay || 10); + var task = new EXTUTIL.DelayedTask(); + if(!l.tasks) { + l.tasks = []; + } + l.tasks.push(task); + task.delay(o.delay || 10, h, scope, TOARRAY(arguments)); }; }; @@ -423,29 +427,33 @@ EXTUTIL.Event.prototype = { h = createTargeted(h, o, scope); } if(o.delay){ - h = createDelayed(h, o, scope); + h = createDelayed(h, o, l, scope); } if(o.single){ h = createSingle(h, this, fn, scope); } if(o.buffer){ - h = createBuffered(h, o, scope); + h = createBuffered(h, o, l, scope); } l.fireFn = h; return l; }, findListener : function(fn, scope){ - var s, ret = -1; - EACH(this.listeners, function(l, i) { - s = l.scope; - if(l.fn == fn && (s == scope || s == this.obj)){ - ret = i; - return FALSE; + var list = this.listeners, + i = list.length, + l, + s; + while(i--) { + l = list[i]; + if(l) { + s = l.scope; + if(l.fn == fn && (s == scope || s == this.obj)){ + return i; + } } - }, - this); - return ret; + } + return -1; }, isListening : function(fn, scope){ @@ -454,35 +462,61 @@ EXTUTIL.Event.prototype = { removeListener : function(fn, scope){ var index, + l, + k, me = this, ret = FALSE; if((index = me.findListener(fn, scope)) != -1){ if (me.firing) { me.listeners = me.listeners.slice(0); } + l = me.listeners[index]; + if(l.task) { + l.task.cancel(); + delete l.task; + } + k = l.tasks && l.tasks.length; + if(k) { + while(k--) { + l.tasks[k].cancel(); + } + delete l.tasks; + } me.listeners.splice(index, 1); ret = TRUE; } return ret; }, + // Iterate to stop any buffered/delayed events clearListeners : function(){ - this.listeners = []; + var me = this, + l = me.listeners, + i = l.length; + while(i--) { + me.removeListener(l[i].fn, l[i].scope); + } }, fire : function(){ var me = this, args = TOARRAY(arguments), - ret = TRUE; + listeners = me.listeners, + len = listeners.length, + i = 0, + l; - EACH(me.listeners, function(l) { + if(len > 0){ me.firing = TRUE; - if (l.fireFn.apply(l.scope || me.obj || window, args) === FALSE) { - return ret = me.firing = FALSE; + for (; i < len; i++) { + l = listeners[i]; + if(l && l.fireFn.apply(l.scope || me.obj || window, args) === FALSE) { + return (me.firing = FALSE); + } } - }); + } me.firing = FALSE; - return ret; + return TRUE; } }; })(); \ No newline at end of file