U
U
UZER20062013-03-27 11:56:22
JavaScript
UZER2006, 2013-03-27 11:56:22

Function substitution in Ext.JS?

There were problems when replacing some functions in the new Ext.JS.
The challenge is to add response text handling to DirectEvent. Processing happens with callback.
With various crutch methods, I almost solved the problem, but now a problem has arisen. When sending text for decryption, I need to stop further execution of the success function. And it's just not there!
Here is part of the code:

Ext.net.DirectEvent = new Ext.data.Connection({
  //...всякие параметры...
  listeners : {
  beforerequest : {
    fn : function (conn, options) {
    //...кроме всего прочего, здесь объявляются локальные функции и переменные
    options.success = function (response, options) {
      var o = options;
      removeMask(o);
      //...
      var parsedResponse = o.scope.parseResponse(response, options);
      //вот здесь надо оборвать, если parsedResponse пустой.
      //...
    }
  },
  //...
});

Of course, I do not want to duplicate and edit the body of the beforerequest listener in my code. Therefore, it was decided to add another listener, in which to replace the success function.
Ext.net.DirectEvent.addListener('beforerequest',function(req,o) {
    debugger;
    eval('o.success = '+o.success.toString().split('var parsedResponse = o.scope.parseResponse(response, options);').join('var parsedResponse = o.scope.parseResponse(response, options); if (!parsedReaponse) return;debugger;'));
    return true;
  });

But in this case (and in any other, probably), the execution context is lost. For example, the function is removeMaskdeclared in the local context of the original beforerequest listener.
Actually, the question is: How to fix the context or in what other adequate way to solve the problem?
It is not possible to remake the function of processing the response body (remove the callback), I immediately ask you not to advise anything like this. It is necessary in any way to correctly break the execution successwith a zero answer parseResponse.
If you do not replace the function success, there is a break on the next line with an error (cannot read property of undefined), but I want it to be normal and without errors. throwdoesn't fit either.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
shai_hulud, 2013-03-27
@UZER2006

and why "return false" is not suitable?
according to the sources, it should abort the execution of the request

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question