Jsf get ajax queue - javascript

Is it possible to get the current jsf-ajax-queue in javascript?
I need to detect if there is currently any jsf-ajax request running.
The
jsf.ajax
object seems not to expose this information.
I dont want to add event listeners becuase this is only for selenium testing and not needed for production.

object seems not to expose this information.
There's indeed no public API for that, as confirmed by the jsf.ajax jsdoc.
Your best bet is to let Selenium programmatically register a global ajax listener beforehand via jsf.ajax.addOnEvent and jsf.ajax.addOnError. This way you can keep track of started, completed and errored requests yourself.

Related

How to emit signal in KWin scripting API

With the KWin scripting API, I know I can connect a signal with
client.signal.connect(myFunction);
to trigger some action when the script receives a signal.
But how can I emit a signal from my KWin script for other components to pick up?
I want something like
client.emit(signal);
but couldn't find anything in the API documentation and unsuccessfully tried various possible syntaxes.
My use case is that I want to emit a clientStartUserMovedResized signal before doing a geometry change, so that another script can detect that a window is about to be changed with the window with the old geometry passed over, before the clientGeometryChanged signal is automatically emitted after the change in geometry has already happened and the old geometry is lost.
As answered on reddit https://old.reddit.com/r/kde/comments/qndb0k/how_to_emit_signal_in_kwin_scripting_api/
Pretty sure you just call it as a normal function.
https://doc.qt.io/qt-5/qtqml-syntax-objectattributes.html#signal-handler-attributes
https://develop.kde.org/docs/plasma/kwin/api/#signals-3
client.clientStartUserMovedResized(client) (not sure why it needs a references to itself as a parameter)
https://invent.kde.org/plasma/kwin/-/blob/master/src/abstract_client.cpp#L970

Listen to server changes

a server has certain variables with values which change on a regular basis. These changes don't emit events or anything. My JavaScript Application receives the values through HTTP-Requests with the Server, where i can access the current variable values of the server.
Since i always want the latest value my approach so far is a normal GET Request inside an interval.
But this does not seem right...
Does anyone have a better idea? I can't use sockets since the server isn't emitting anything, right?
Thanks!
In a node.js app (server), you could :
set up a socket.io connection with your client
create an event EventEmitter A
subscribe to your event emitter
do a setInterval to check your variables
when one of your variables has changed -> A.emit('variable-name', newValue)
You recieve the event from A and send it to your client through socket.io

Is there any option for setInterval()?

I am reading a file continuously after a some time as
setInterval(function(){
$.getJSON("json/someFile.json", function(data){
// Some code
});
}, 5000);
I am reading this file continuously after a delay as it is getting updated in other part of the code. I want to avoid using setInterval().
Is there any way, by which I will be able to know that the file is updated and read it only when it is updated.
Firstly, setInterval is a native JavaScript method. It does not come from jQuery. Second what you've done is called polling. Meaning that you request some information periodically in order to keep it up to date. The alternative is using a WebSockets. Websockets are a two way connection between the client and the server, which can both push and receive messages. This way, you can send a socket message to the client whenever the file is updated in the backend.
I'm assuming you're talking about client side code. Then no: there is no way to "watch" a json file like you could have a file watcher in "regular" applications. You need either:
Interval-based checking as you're doing now. However, as suggested in comments by #George, you might be better off if you use setTimeout and only re-fire the Ajax request in specific situations (e.g. on success, perhaps not on failures); With your current approach the function may run on the interval, but if it takes longer than the interval timing to respond you get a build-up of requests;
Websockets (potentially with fallback to something like long-polling), perhaps using another library for that + the server-side part of this solution;
No other way I'm afraid.
As a footnote, this hasn't got much to do with jQuery. First, the setInterval is not of jQuery but a regular window function, and second the problem of "watching" a file isn't specific to how you're doing the Ajax call (you're using jQuery, but you could use another lib for it too).

Running code from Socket.io notification

I'm running a NodeJS server which is sending notifications to the clients when somebody does something, for example, when a client deletes a row from a grid, Socket.io informs the rest of the clients that a row got deleted.
In that example, I could add something like actionType: rowdeleted to the socket.io message and then just detect the actionType on the client side and refresh the grid. Anyways, the problem is that there can be infinite number of actions (and new ones can be added), so I can't code a function for each action type on the client side.
Then I thought maybe I can send some code via socket.io and make the client run it, but I'm not sure if that is the best way for doing what I want. Also, how are the clients going to run that code? Via eval?
I'm open to any suggestion :)
Have you considered something similar, but not as eval. You clearly must have the code to execute somewhere, be it on the server side. Why not create a way to let the client know what script/code/action to get and execute it.
I have used something similar out of a similar need. The action type referenced a script in a specific path on my server (/js/actions/ACTION.js). Upon getting the command to run the action, the client would check if it has the action, if not, it would go get the action. After that it would run the action on the script. RequireJS is good for this kind of thing. It will keep track of what actions you have and what actions you don't have. It will also make sure to get the action if it doesn't have it before it run some function that needs it.
eval is evil (c)
so I can't code a function for each action type on the client side.
there's no point emiting events from server if they wont be handled on the client(s)
have a client handle funcion for each type of event your server is emiting.
Otherwise bind on all events and handle then

How to bind server side events on client objects and vice versa with meteor

Is it possible to directly bind server side events to client side objects in meteor?
I would like to update a view for example when a server side event triggers. On the other hand I'd like to fire a server side method when a user clicks a view item.
I could use Meteor#methods for all the events but that seems odd.
Or can I specify an eventhandler for example using EventEmitter outside the client- and server-scope so that it is available on both sides and trigger/bind events ob that very object?
Some confused about that I am thankful for hints into the right direction.
Regards
Felix
Update:
Using Meteor#methods works great in case user events should be mapped to server side actions. The other way around is still unclear. Asynchronous actions on serverside could persist their results in a collection which is pub/sub'ed to the client, which in turn could update some view due to the reactive context. But thats odd, cause persisting that kind of info is slow, wasted space and time. Any suggestions?
I believe you can use the Collection.observe on the server side to 'observe' events on the Collection as clients are inserting, updating, removing, etc... That might be a start if you are focused on Collections alone. I used it like a sort of server side event loop to watch for collection changes.
When a user clicks on something in a view try binding a Template Event to the View css selector and then calling a Meteor method which will notify the server of the event. See the examples of binding a key handler and/or button handlers to a Template.entry.event which then call a Meteor method notifying the server that something happened.
What about storing the progress in Session? You could do something like this:
Template.progress.value = function() {
return Session.get('progress');
}
Then, whenever you update the Session on the server, the client template will automatically get those changes.
Out of curiosity, how exactly are you performing asynchronous actions on the server? I'm still trying to figure that out.

Categories

Resources