eventemitter

How pass 2 parameters to EventEmitter angular2

十年热恋 提交于 2019-11-30 04:36:29
I have in my component a EventEmitter but I can't compile because return this error: "Supplied parameters do not match any signature of call target" My component: @Output() addModel = new EventEmitter<any>(); saveModel($event, make, name) { this.addModel.emit(make, name); } If i delete one of parameters in this.addModel.emit() it work, but so, Can i pass 2 parameters and how, to my eventEmitter? I tried also with : @Output() addModel = new EventEmitter<any,any>(); but It doesn't work If you look at the EventEmitter API's emit method, it can only take single parameter of type T emit(value?: T)

How do I write non-blocking code in Node.js?

我与影子孤独终老i 提交于 2019-11-30 03:11:56
I can write non-blocking I/O in Node.js very easily. It's what the entire library is set up for. But any computation done is blocking. Any message passing over event emitters are blocking . For example, emitting events are resolved immediately and are thus blocking: var e = new process.EventEmitter; e.on("foo", function() { console.log("event"); }); process.nextTick(function() { console.log("next tick"); }); setTimeout(function() { console.log("timeout"); }, 0); e.emit("foo"); > event > next tick > timeout Apart from wrapping calls in nextTick , how do I make code non-blocking? I want to do as

javascript eventemitter multiple events once

北战南征 提交于 2019-11-30 01:16:34
问题 I'm using node's eventemitter though other event library suggestions are welcomed. I want to run a function once if several events are fired. Multiple events should be listened to, but all of them are removed if any one of the events fires. Hopefully this code sample demonstrates what I'm looking for. var game = new eventEmitter(); game.once(['player:quit', 'player:disconnect'], function () { endGame() }); What is the cleanest way to handle this? Note: Need to remove bound functions

React Hooks useState+useEffect+event gives stale state

与世无争的帅哥 提交于 2019-11-29 14:08:35
问题 I'm trying to use an event emitter with React useEffect and useState , but it always gets the initial state instead of the updated state. It works if I call the event handler directly, even with a setTimeout . If I pass the value to the useEffect() 2nd argument, it makes it work, however this causes a resubscription to the event emitter every time the value changes (which is triggered off of keystrokes). What am I doing wrong? I've tried useState , useRef , useReducer , and useCallback , and

Nodejs EventEmitter - Define scope for listener function

不羁岁月 提交于 2019-11-29 13:58:07
I'd like to have something like this work: var Events=require('events'), test=new Events.EventEmitter, scope={ prop:true }; test.on('event',function() { console.log(this.prop===true);//would log true }); test.emit.call(scope,'event'); But, unfortunately, the listener doesn't even get called. Is there any way to do this w/ EventEmitter? I could Function.bind to the listener, but, I'm really hoping EventEmitter has some special (or obvious ;) way to do this... Thanks for the help! No, because the this value in the listener is the event emitter object. However what you can do is this var scope =

Angular 2 event broadcast

你离开我真会死。 提交于 2019-11-29 01:30:22
New to Angular 2. I'm working on broadcast a event between same level component. Currently I know EventEmitter just can transfer a event to upper level component. I have checked this this link and know observable may be a way to solve my problem, but the sample in that url seems not work for me. Does anyone know how to use it(observable) for broadcast event or some other way to transfer event to same level components? You just need to create some service that will emit messages on which you can subscribe. It can be Observable from rxjs , EventEmitter from node.js , or anything else that

Communicate between sibling components Angular 2

醉酒当歌 提交于 2019-11-29 01:13:45
问题 I tried to follow this answer but its too confusing Angular 2 event catching between sibling components I want to call a method in child component 1 when something is clicked on child component 2 Child component 2 emits an event called trackClick. Parent Component: <div> <audio-player></audio-player> <audio-albums></audio-albums> </div> Child Component 1 (audio-player) // Don't know what to do here, want to call this function trackChanged(track){ console.log("YES!! " + track); } Child

Child listens for parent event in Angular 2

為{幸葍}努か 提交于 2019-11-28 16:37:33
In angular docs there is a topic about listening for child events from parents. That's fine. But my purpose is something reverse!. In my app there is an 'admin.component' that holds the layout view of admin page (sidebar menu,task bar, status etc..). In this parent component I configured router system for changing the main view between other pages of administrator. The problem is for saving things after change, the user clicks on save button in task bar (that is placed in admin.component) and the child component must listen to that click event for doing save staff. Thierry Templier I think

Nodejs EventEmitter - Define scope for listener function

て烟熏妆下的殇ゞ 提交于 2019-11-28 07:27:48
问题 I'd like to have something like this work: var Events=require('events'), test=new Events.EventEmitter, scope={ prop:true }; test.on('event',function() { console.log(this.prop===true);//would log true }); test.emit.call(scope,'event'); But, unfortunately, the listener doesn't even get called. Is there any way to do this w/ EventEmitter? I could Function.bind to the listener, but, I'm really hoping EventEmitter has some special (or obvious ;) way to do this... Thanks for the help! 回答1: No,

Unable to figure out correct EventEmitter or Observable Syntax in Angular2 Services

限于喜欢 提交于 2019-11-27 20:10:19
I'm having a hard time finding much in the way of examples/guides for using observables in an Angular2 service. There is stuff for html templates binding with EventEmitter but that doesn't seem right for a service. One of the big driving themes is getting away from Promises in Angular2 but I can't seem to get the new syntax correct. What I'm Doing I have a FirebaseAuth Service that can be injected into other services or components. I have a function that does an async call to firebase, in my example to create a user I want to return a Observable(to replace the promise) that other services can