event-handling

Difference between Events and Functions?

对着背影说爱祢 提交于 2019-11-30 20:58:00
I am new to Node, and I am struggling to understand the main difference between Events and Functions. Both need to be triggered, so why do we need an Event at all if we have to trigger it anyway? How is it different than having a Function triggered? Example code: var events = require('events'); var eventEmitter = new events.EventEmitter(); eventEmitter.on('event1', function () { console.log('Event 1 executed.'); eventEmitter.emit('event2'); }); eventEmitter.on('event2', function() { console.log('Event 2 executed.'); }); eventEmitter.emit('event1'); console.log('Program Ended.'); We can achieve

c# WPF how to repeat MediaElement playback from mediaended event handler without declaring new source?

痴心易碎 提交于 2019-11-30 20:20:15
im playing a video in WPF.i want it to loop so what i did is when the mediaended event fires, i play back my video. so this will get me a loop. prob is why do u i have to create new source again? why cant i just call 'play'? i dont want to do it in XAML as for some reason. have a look at my code snippet: string startPath System.IO.Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName); public Window1() { InitializeComponent(); media.Source = new Uri(startPath + @"playlist.wpl"); media.play(); } private void Media_Ended(object sender, EventArgs e) { media.Source = new Uri

UI update in WPF elements event handlers

回眸只為那壹抹淺笑 提交于 2019-11-30 19:46:53
There is a problem with UI update in WPF. I have such code: private void ButtonClick_EventHandler(object sender, RoutedEventArgs e) { Label.Visibility = Visibility.Visible; TextBox.Text = "Processing..."; LongTimeMethod(); //some long operation } The problem is that until LongTimeMethod ends (that is event handler ends), Label.Visibility and TextBox.Text will not be changed. I solved it like this so far: private void ButtonClick_EventHandler(object sender, RoutedEventArgs e) { Label.Visibility = Visibility.Visible; TextBox.Text = "Processing..."; Dispatcher.BeginInvoke(new Action

When is Node.js blocking?

孤人 提交于 2019-11-30 19:18:05
I have used Node.js for a while now and I just realized it can be blocking. I just cannot wrap my brain around the conditions under which Node.js becomes blocking. So, Node.js is single-threaded because (i) Javascript is and (ii) avoids all the multi-threaded pitfalls. To do a lot of things at once, despite being single-threaded, it implements asynchronous execution. So, talking with the DB (the I/O in general) is non-blocking (because it is asynchronous). But, all the incoming requests to do some work (i.e. talk with the DB) and all the results of that work that must go back to the client (i

Are JQuery events usables with Dom addEventListener?

送分小仙女□ 提交于 2019-11-30 18:59:35
问题 I'm using Bootstrap4 alpha in my project, and for some investigations purposes, i'm trying to catch a JQuery event using DOM addEventListener() . The event is fired using the JQuery $("#mypanel").trigger("shown.bs.collapse") function by bootstrap in it's collapse component. If i try to catch it using the JQuery $("#mypanel").on("shown.bs.collapse", ... ) function, everything works just fine. But if i use $("#mypanel").get(0).addEventListener("shown.bs.collapse", ... ) on the corresponding DOM

Are event handler, event listener, and event registration all referring to the same thing?

China☆狼群 提交于 2019-11-30 18:57:33
If not, what is their difference? The listener is the object that receives notification, the handler is the method that actually handles the notification. Registration means to register a new listener to the event source. The Event Handler is the method that gets called to handle the Event. The Event Listener is the mechanism that listens for the Event to happen. It then calls the Event Handlers. Event Registration is the process by which an Event Handler gets registered with an Event Listener so that the handler is called when the Event Listener fires the event. Event handlers and event

javascript bind an event handler to horizontal scroll

半世苍凉 提交于 2019-11-30 18:16:00
Is there a way in javascript to bind an event handler to a horizontal scroll as opposed to the generic scroll event which is fired when the user scrolls horizontally and vertically? I want to trigger an event only when the user scrolls horizontally. I searched around for an answer to this question, but couldn't seem to find anything. Thanks! P.S. My apologies if I'm using some terminology incorrectly. I'm fairly new to javascript. UPDATE Thanks so much for all your answers! In summary, it looks like you are all saying that this isn't supported in javascript, but I that I can accomplish the

Chrome extension: onclick() event not triggering alert() popup [duplicate]

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-30 18:04:22
问题 This question already has answers here : onClick within Chrome Extension not working (4 answers) Closed 5 years ago . Unable to trigger alert() popup with onclick() event code: manifest.json: { "name": "Project", "version": "1.0.0", "manifest_version": 2, "description": "Popup when website requires Log in", "browser_action":{ "default_icon":"icon_19.png", "default_popup":"Popup.html" } } Popup.html: <html> <head></head> <body> <div class="plus" onclick="popup()"></div> <script src="inline.js"

Android: ViewGroup, how to intercept MotionEvent and then dispatch to target or eat it on demand?

Deadly 提交于 2019-11-30 17:56:40
问题 Given that there is a ViewGroup with several children. As for this ViewGroup, I'd like to have it managing all MotionEvent for its all children, which says VG will 1. be able to intercept all events before they get dispatched to target (children) 2. VG will first consume the event, and determine if will further dispatch event to target child 3. DOWN, MOVE, UP, I'd like to see them as relatively independent, which means VG could eat DOWN, but give MOVE and UP to children. I've read SDK guide

WPF: How to prevent a control from stealing a key gesture?

萝らか妹 提交于 2019-11-30 17:32:10
In my WPF application I would like to attach an input gesture to a command so that the input gesture is globally available in the main window, no matter which control has the focus. In my case I would like to bind Key.PageDown to a command, however, as soon as certain controls receive the focus (e.g. a TextBox or TreeView control), these controls receive the key events and the command is no longer triggered. These controls have no specific CommandBindings or InputBindings defined. This is how I define my input gesture: XAML: <Window x:Class="Window1" xmlns="http://schemas.microsoft.com/winfx