How to emit signal in KWin scripting API - javascript

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

Related

How to handle webhook fulfillment in Dialogflow using nodejs

I am looking for some advice on how to design the code to handle the fulfillment of requests sent by Dialogflow to my server. Dialogflow only lets setup a single webhook to handle all the intents. Let's say that I have 5 different intents; all of them will call the same webhook on my server. Now, how can I elegantly manage server-side different workflows depending on the intent?
The parameter that I would ideally use to make a distinction is contained in req.body.queryResult.intent.displayName; and indicates the name of the current intent. Right now I have two ideas, using express redirect method using the intent as part of the path, or creating a dictionary of handlers where the intents are the key.
Do you have any suggestions?
The dialogflow-fulfillment library, although deprecated, uses your latter approach - creating a Map from Intent name to Handler function and handing this map to a Dispatcher. It is a simple, straightforward, and speedy approach.
The multivocal library takes a similar, tho more expansive, approach, letting you register a handler against either the Intent name or the Action value assigned and having separate configurations for the response based on either Intent, Action, or another value that is set in the handler.
Redirecting to a new, path-based, method does not seem to give you anything.

How to abort creation into firebase realtime database from a cloud function?

I'm creating an application that uses two step object creation into firebase realtime database.
What I want is that on a cloud function that catches onCreate event, if some rules are not complete, then the create action be stopped.
Is there a way to do that? Or I need to remove the node instead of reject the creation?
Thank you!
You might want to consider a command-response model for database writes. Instead of writing directly into the database and expecting that a function cancel the write, push a "command" object into the database that describes what you want to do, at a different location, and have a function respond to that command to determine what should actually be done. Your function can then determine whether or not to commit a final write if the conditions are OK.
I gave a talk at Google I/O 2017 that outlines this strategy with respect to a multi-player turn based game that intercepts all move requests to determine if they're valid before committing them to the game. The part about command-response starts here.
There currently is no way to reschedule a trigger. So indeed, you'll either have to create a new node or trigger a re-check in some other way, e.g. a regular cron trigger to clean up the previously unhandled nodes (blog, video).

Jsf get ajax queue

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.

backbone.js adding a custom sync to make a loading effect

i'm building a app with backbone.js, now i wanna adding a global loading effect when backbone.js is making http request to the server, this is a single page webapp, so there are lots of asynchronous http requests. I think i can modify the Backbone.sync method to make this easy. How can i do this?
Post a sample of code
// let's say there is a function to generate the loading and remove it
// mask.create();
// mask.remove();
var BookList = Backbone.Collection.extend({
model:Book,
url:'/api/list/1',
});
var list = new BookList();
list.bind('reset', function(){
$('.content').html('');
list.each(function(book){
self.addOne(book);
})
});
list.fetch();
It sounds like you're looking to connect your display to the sync for UI feedback. You don't want to muddling concerns though so you don't want the sync itself to care about the presentation. The default sync implementation provides some events (and there's likely more covered in the docs):
Whenever a model or collection begins a sync with the server, a
"request" event is emitted. If the request completes successfully
you'll get a "sync" event, and an "error" event if not.
So you could start with binding to those events, but either way you should stick to some kind of approach where "sync" remains focused on its responsibility.
#MattWhipple is absolutely correct about separation of concerns: you shouldn't mix UI logic to the persistence layer. However that doesn't mean that you shouldn't override the Backbone.sync method, as long as you provide a decoupling mechanism to separate the concerns.
One such mechanism is the mediator pattern, i.e. using a global event bus to publish and consume messages. As it happens, Backbone provides just such a mechanism with the evented global Backbone object. You can override your sync to trigger an event:
Backbone.trigger("request:start");
And listen to it in the UI layer:
Backbone.on("request:start", callback);
In this way neither layer has to know of each other, and you can still achieve the global request handling.
Furthermore, if all you want is to catch all AJAX requests and you don't care whether they originated from Backbone, you can drop one level lower to listen to jQuery's global events and leave Backbone out of it altogether.

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