accessing javascript function arguments - smalltalk

Documentation for JQAjaxSetup>>onError: says:
onError: anObject
"A function to be called if the request fails. The function is passed three
arguments: The XMLHttpRequest object, a string describing the type of error that occurred
and an optional exception object, if one occurred. Possible values for the second argument
(besides null) are 'timeout', 'error', 'notmodified' and 'parsererror'."
I'd like to display the error message using something like
anAjax onError: ((html jQuery id: someId) before: (MyInstanceOfWAPainter error: 'An error message'));
How do I do that? Possibly doing it all on the client side.

Because the error happens client-side and you probably have a failing connection in such an event, you need to generate the complete javascript code that will display the error (i.e. without rendering callbacks to Seaside).
The snippet below will generate a JS function with two arguments. The body of the function is the jQuery expression that will put the error message (inside the _error variable) right before the html dom element with id someId.
anAjax
onError: (((html jQuery id: someId) before: (JSStream on: '_error'))
asFunction: #('_XMLHttpRequest' '_error'));
Personally, I would not use Seaside's JS-generation functionality here if the id in someId is not dynamically generated. If it's dynamically generated from within Seaside, the first snippet might still be easier.
anAjax onError: (JSStream on: 'function(_XMLHttpRequest,_error){
$(''#someId'').before(_error)})

According to documentation you can do below to show the error:
onError:function(_XMLHttpRequest, _error) {
alert(_error);
}

this basic idea would be:
jQuery ajax onError: (self javascript alert: 'error')
see JQAjaxTest>>testOnError.

Related

Access value passed in previous step while handling error in Reactor

I have a use case where I want to access value passed in previous step while handling error in Reactor code. something like this
return activityRepository.createActivity()
.doOnNext(activity->{
// do something with activity Object
})
.someErrorPipelineStep((throwable,activityId)-> {
// do something with activity Object
return Mono.error();
})
Is there a way to access the activity object inside doOnError or any other error handler.
I cannot use OnErrorContinue as the second parameter is of type Object instead of Activity ?

Debugging of Lodash chain functions

How to debug lodash chain functions in browser.
Ex:
if (_.size(_.values(_.omit(this.user, 'language')).filter(Boolean)) < 2)
If we want to debug _.omit(this.user, 'language') and then the end result with another function _.values() as shown in the example,what should be done.
I tried searching but can only find console.log but if we want to debug right in the browser how can we do it.
Chain functions and lodash sequences are usually "debugged" or "tapped" into via _.tap or _.thru:
tap: This method invokes interceptor and returns value. The interceptor is
invoked with one argument; (value). The purpose of this method is to
"tap into" a method chain sequence in order to modify intermediate
results.
so something like this:
const obj = { name: 'Ace', language: 'English', age: 3 }
const result = _(obj)
.tap(x => console.log(x))
.omit('language')
.tap(x => console.log(x))
.omit('age')
.tap(x=> console.log(x))
.value()
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.10/lodash.min.js"></script>
thru: This method is like _.tap except that it returns the result of
interceptor. The purpose of this method is to "pass thru" values
replacing intermediate results in a method chain sequence.

What does JQuery do with randomly generated callback name for JSONP?

so since Ajax generates something like this for the request
callback=jQuery19104342058659531176
and in the end server returns
jQuery19104342058659531176(data)
what does it call if jQuery19104342058659531176() function is (obviously) not defined?
I understand it will go to success/error handler, but dont really get the purpose of the callback then?
in fact, jQuery will invoke the callback, then invoke success/error.
If you omit "jsonpCallback", then jQuery will invoke the default one deined by jQuery. the source code is in jsonp.js:
window[ callbackName ] = function() {
responseContainer = arguments;
};

EXTJS Ext.Ajax.request() issues

So I think I maybe missing something with Ext.Ajax.request();
So I have code that does the following:
Ext.Ajax.request({
url : 'myurl',
success : function(){
alert('success 1');
},
callback : function(){
alert('callback');
}
});
Then later I make another ajax call like this:
Ext.Ajax.request({
url : 'myurl',
success : function(){
alert('success 2');
}
});
If i don't define a callback function the old one from the first call is still set. So when it runs it still calls the old callback function defined earlier. So I add listeners to the
Ext.Ajax.on('beforerequest', function(c, o, e){
//The options has all my previous options
});
So I put a break point in here and looked at the options, and if on my second call or any other ajax call after do not override callback or any other options with an emptyFunction() or any other request config the previous values stays. So if on my second call I didn't redefine the success function the first calls success function would still be there. Is there a way to clear all previous options, on the next call? I could just clear them on each new call. But I don't understand why if the calls are unrelated my options from the last call remain?
As the docs states, Ext.Ajax is a singleton.
If you look at its code, you'll see the the option config will remain between calls.
So I'm afraid to say that you are using it the wrong way. Ideally, you should define what happens upon success or failure with each call.
It does appear though that this will work:
var iAjax = new Ext.data.Connection();
iAjax.request({
// unique config here.
});

How to register component interface in wxwebconnect?

I'm doing an experiment with wxWebConnect test application, incorporating the xpcom tutorial at "http://nerdlife.net/building-a-c-xpcom-component-in-windows/"
I adapt MyComponent class as necessary to compile together with testapp.exe (not as separate dll), and on MyApp::OnInit I have the following lines:
ns_smartptr<nsIComponentRegistrar> comp_reg;
res = NS_GetComponentRegistrar(&comp_reg.p);
if (NS_FAILED(res))
return false;
ns_smartptr<nsIFactory> prompt_factory;
CreateMyComponentFactory(&prompt_factory.p);
nsCID prompt_cid = MYCOMPONENT_CID;
res = comp_reg->RegisterFactory(prompt_cid,
"MyComponent",
"#mozilla.org/mycomp;1",
prompt_factory);
Those lines are copied from GeckoEngine::Init(), using the same mechanism to register PromptService, etc. The code compiles well and testapp.exe is running as expected.
I put javascript test as below :
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
const cid = "#mozilla.org/mycomp;1";
obj = Components.classes[cid].createInstance();
alert(typeof obj);
// bind the instance we just created to our interface
alert(Components.interfaces.nsIMyComponent);
obj = obj.QueryInterface(Components.interfaces.nsIMyComponent);
} catch (err) {
alert(err);
return;
}
and get the following exception:
Could not convert JavaScript argument arg 0 [nsISupport.QueryInterface]
The first alert says "object", so the line
Components.classes[cid].createInstance()
is returning the created instance.
The second alert says "undefined", so the interface nsIMyComponent is not recognized by XULRunner.
How to dynamically registering nsIMyComponent interface in wxWebConnect environment ?
Thx
I'm not sure what is happening here. The first thing I would check is that your component is scriptable (I assume it is, since the demo you copy from is). The next thing I would check is whether you can instantiate other, standard XULRunner components and get their interface (try something like "alert('Components.interfaces.nsIFile');" - at least in my version of wxWebConnect this shows an alert box with string "nsIFile".
Also, I think it would be worth checking the Error Console to make sure there are no errors or warnings reported. A magic string to do that (in Javascript) is:
window.open('chrome://global/content/console.xul', '', 'chrome,dialog=no,toolbar,resizable');