View Full Version : Howto remove an InterCeptor?
Wolfgang
12 Aug 2007, 2:12 AM
Hello,
can anyone guide me on how to remove an Interceptor created like this?
MY.util.prototype.fireEvent.createInterceptor(Base.process, Base);
The interceptor works, but how can i remove it dynamically when i do not need it anymore?
evant
12 Aug 2007, 6:05 AM
Why not just keep a reference to it?
var old = MY.util.fireEvent;
My.util.fireEvent = My.util.fireEvent.createInterceptor(Base.process, Base);
My.util.fireEvent = old;
franklt69
12 Aug 2007, 6:40 AM
a doubts, when is useful to use Interceptor?
regards
Frank
Wolfgang
13 Aug 2007, 2:33 AM
@evant
Do you think it is really that easy? I thought i would need something like removeInterceptor
(Which is not part of EXT).
@franklt69
a doubts, when is useful to use Interceptor?
Basically when you want to be part of the event handler chain and need to intercept an event to do some custom stuff before further processing.
evant
13 Aug 2007, 1:49 PM
Try it:
function f1()
{
alert('in f1');
return true;
}
function f2()
{
alert('in f2');
return true;
}
Ext.onReady(function()
{
var old = f1;
f1 = f1.createInterceptor(f2);
f1();
f1 = old;
f1();
}
);
jack.slocum
13 Aug 2007, 3:59 PM
This kind of a side note but in 2.0, with Observable objects you can actually "subscribe" to methods (and unsubscribe). e.g.
myObj.beforeMethod('myMethod', Base.process, Base);
and
myObj.removeMethodListener('myMethod', Base.process, Base);
This means multiple "interceptors" and "sequences" can be added just like event handlers (a must for plugins, for example).
Another difference with the method listeners vs interceptor is they can also override the return value of the function.
Wolfgang
13 Aug 2007, 10:48 PM
@evant
Thank you for the example.
@Jack
Thanks for the info about V2.0.
Regards
Wolfgang
Powered by vBulletin® Version 4.1.5 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.