How do I bind an action to a "create/remove new node" event in DynaTree? - add

Getting started with DynaTree. I'd like to bind some code to the event which is "adding a new node". The onCreate option seems to be fired when a node is rendered for the first time. Yes, this includes when a node is created, but it also includes when the tree is loaded and rendered, and when a collapsed subtree is expanded for the first time. So it doesn't seem appropriate. The same question applies to removing a node. Where are these events?
Thanks,
Marco.

So you want to execute code when you add a child? I did this by creating my own little function to add Nodes.
function addChildNode(NodeID, NodeName, ParentID){
jQuery("#tree2").dynatree("getTree").getNodeByKey(ParentID).addChild({title: NodeName, key: NodeID});
//Code you wish to be executed goes here
}
Then you simply call the function and pass in the NodeID (key), NodeName (title), ParentID (key).

Related

Get Rid of a QAction.trigger.connect in pyside2

I have the following function to bind my dynamically generated Actions in the ToolBar with a name passing function:
def bind_action(self, action, name):
'''bind an Action to the ToolBar'''
action.triggered.connect(lambda: self._fct.get_name(name))
Now the user may change the name at runtime. And I call the function a second time to bind the new name. If the QAction is triggered now, I have the problem that both triggers are sent. Is it possible to delete the first connect again? I found a workaround (I check if the name is in a list), but I want to have it neater.
As private feedback I got this question recommended: stackoverflow.com/questions/45090982/… It is the exactly opposite problem. There, a user want to know how he can add a second parameter, my Question is: How can I get rid of the first triggered.connect()?

Cell events are not triggered

I have a working paper with graph. I have added several cells to the graph and I'm trying to listen to the cell:highlight event but I never receive it.
I'm doing:
paper.on('cell:highlight', function() { ... });
Other events seem to work fine, for example: blank:pointerup,...
Is there something special to do to make cell events work ?
According to documentation:
cell:highlight - triggered when highlight() method is called on either
an element or a link. Note that this method is also called
automatically when the user is reconnecting a link and the connection
is valid (validateConnection() returns true) or if embeddingMode is
enabled on the paper and the dragging element is above another element
it could be dropped into (validateEmbedding() returns true). The
handler for this event has the following signature: function(cellView,el). The handler defaults to function(cellView, el) {
V(el).addClass('highlighted') }. In other words, the 'higlighted' CSS
class is added and so you can style the highlighted element in CSS. If
you want to use a different method for highlighting cells, call
paper.off('cell:highlight') first to unregister the default handler
and then paper.on('cell:highlight', myHandler) to register your own.
You can read more about it here.

how to remove listener from inside the callback function in node.js

I set up a listener for an event emitter and what I want to do is to remove the same listener if I get certain events. The problem I am running into is that I don't know how to pass the callback function to removeListener inside the callback function. I tried "this", but it errors out. Is there any ways to achieve this? By the way, I am not using once because I am only removing the listener on a certain event.
P.S. I am using redis here so whatever message I receive I would always be listening on the key "message". It would not be possible to just listen on different keys. Channel wouldn't help either because I only want to remove a specific listener.
Also, what I want to do is communication between two completely independent process. No hierarchy of any kind. In process B, there are many independent functions that will get data from process A. My initial thought was using a message queue, but with that I cannot think of a way to ensure that each function in B will get the right data from A.
One cool thing about closures is that you can assign them a name, and that name can be used internally by the function. I haven't tested this, but you should try:
object.on('event', function handler() {
// do stuff
object.off('event', handler);
});
You should also look into whether your event emitter supports namespaces. That would let you do something like:
object.on('event.namespace', function() {
// do stuff
object.off('.namespace');
});

What is the correct way to hang up a video call in vLine?

I am currently using Client.stopMediaSessions(). Is this correct? From what I read in the documentation, and see in the examples, this seems to be the right way to do it.
This should stop both local and remote streams, correct?
What event(s) is/are fired when stopMediaSessions() is called? From my logs, it doesn’t seem that the handler for mediaStream:end is being called. Should it be? Or is enterState:closed the only event fired? Or are both fired?
My question has to do with removing the <video> elements from the DOM – both for the remote and local elements. In your example for MediaStream in the API Reference, the addStream() function handles both mediaStream:start and mediaStream:end events. However, when using this to add both local and remote streams, you can’t count on the mediaElement variable in the mediaStream:end handler because nothing ties that var to the stream, so you don’t know which element to do a removeChild() on.
Anyway, that’s not a big deal. I am just curious what the sequence of events is when a stopMediaSessions() is called; from that I can ensure the right <video> element is being removed.
But in general, I do want to know what the correct way is to hang up/terminate a video call among a set of participants.
Thanks a lot!
client.stopMediaSessions() will stop all vline.MediaSessions for the given vline.Client, so yes, it will "hang up" a call.
To "hang up" an audio/video session with a specific user (vline.Person), you can use Person.stopMedia().
A vline.MediaSession can have local and remote vline.MediaStreams associated with it, so by stopping a vline.MediaSession you will implicitly stop all vline.MediaStreams associated with it.
Since client.stopMediaSessions() is stopping all of the vline.MediaSession's (and therefore vline.MediaStream's), you should get both a mediaStream:end event (from the vline.MediaStream) and a enterState:closed event (from the vline.MediaSession).
For adding and removing <video> elements and keeping track of them, I'd suggest doing something similar to what the vLine shell example does. It uses the unique MediaStream ID to name the div that it puts the <video> element in:
mediaSession.on('mediaSession:addLocalStream mediaSession:addRemoteStream', function(event) {
var stream = event.stream;
// guard against adding a local video stream twice if it is attached to two media sessions
if ($('#' + stream.getId()).length) {
return;
}
$('#video-wrapper').append(elem);
});
// add event handler for remove stream events
mediaSession.on('mediaSession:removeLocalStream mediaSession:removeRemoteStream', function(event) {
$('#' + event.stream.getId()).remove();
});

How to remove different listeners on the same object that are also listening to the same event?

Does an event and a listener on a certain object act as an "identifying pair" for that listener? Or just the event on the object?
reading over node.js documentation here:
http://nodejs.org/api/events.html#events_emitter_removelistener_event_listener
For example, if you have two callback functions listener_1 and listener_2:
var stdin = process.stdin;
stdin.on('data',listener_1);
stdin.on('data',listener_2);
then you remove the listener, with:
stdin.removeListener('data',listener_1);
So, is listener_2 still listening?
Thank you.
ps. I tried test myself using util.inspect and listeners method but still not confident I understood how this works!
If you want to remove all the listeners, you can use
stdin.removeAllListeners('data')
Otherwise, after calling
stdin.removeListener('data',listener_1);
listener_2 is still listening.
You can use an anonymous function but you need to save it somewhere.
var listener = function(){};
emitter.on('event', listener);
emitter.removeListener('event', listener);
But that means you can't use bind or the arrow function closure notation:
emitter.on('event', listener.bind(this));// bind creates a new function every time
emitter.removeListener('event', listener.bind(this));// so this doesn't work
emitter.on('event', ()=>{});// closure creates a new function every time
Which is annoying. This works though:
emitter.on('event', this.eventListener = () => {});
emitter.removeListener('event', this.eventListener);
So does this (storing listeners in a map):
emitter.on('event', this.listeners['event'] = this.myEventListener.bind(this));
emitter.removeListener('event', this.listeners['event']);
This is not always an issue:
In the most common case there is only one listener.
In the second most common case, there can be more than one but they all want removing together (e.g. because the emitter has finished its job).
Either way, you won't need to specify the function. However when you do, you do.

Resources