eventemitter

Node.js EventEmitter: How to bind a class context to the event listener and then remove this listener

眉间皱痕 提交于 2019-12-01 17:03:53
Is there a way to access to the class context in the event listener method with possibility to remove the listener? Example 1: import {EventEmitter} from "events"; export default class EventsExample1 { private emitter: EventEmitter; constructor(private text: string) { this.emitter = new EventEmitter(); this.emitter.addListener("test", this.handleTestEvent); this.emitter.emit("test"); } public dispose() { this.emitter.removeListener("test", this.handleTestEvent); } private handleTestEvent() { console.log(this.text); } } In this example removing the listener works, but the handleTestEvent()

Node.js EventEmitter: How to bind a class context to the event listener and then remove this listener

血红的双手。 提交于 2019-12-01 14:55:57
问题 Is there a way to access to the class context in the event listener method with possibility to remove the listener? Example 1: import {EventEmitter} from "events"; export default class EventsExample1 { private emitter: EventEmitter; constructor(private text: string) { this.emitter = new EventEmitter(); this.emitter.addListener("test", this.handleTestEvent); this.emitter.emit("test"); } public dispose() { this.emitter.removeListener("test", this.handleTestEvent); } private handleTestEvent() {

Similarity/Difference between SocketIO and EventEmitter in NodeJS

扶醉桌前 提交于 2019-11-30 23:11:51
I am little confuse between Socket.io and EventEmitter API in nodejs. Yes, I am quite new in event driven NodeJS programming. Is there any significant difference between this two ? or one have made over the other one ? are they designed to serve the same purpose or different ? Any example/resource link, illustrating difference between them would be nice.. You shouldn't compare the EventEmitter API and Socket.IO, as they are completely different things and are unrelated except for the fact that Socket.IO uses events, both on the server side and client side. The EventEmitter API is used by

javascript eventemitter multiple events once

邮差的信 提交于 2019-11-30 18:07:37
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 individually because there will be other listeners bound. fableal "Extend" the EventEmitter like this: var

Similarity/Difference between SocketIO and EventEmitter in NodeJS

只愿长相守 提交于 2019-11-30 17:50:11
问题 I am little confuse between Socket.io and EventEmitter API in nodejs. Yes, I am quite new in event driven NodeJS programming. Is there any significant difference between this two ? or one have made over the other one ? are they designed to serve the same purpose or different ? Any example/resource link, illustrating difference between them would be nice.. 回答1: You shouldn't compare the EventEmitter API and Socket.IO, as they are completely different things and are unrelated except for the

How to unsubscribe from EventEmitter in Angular 2?

梦想的初衷 提交于 2019-11-30 17:30:06
export declare class EventEmitter<T> extends Subject<T> { /** * Creates an instance of [EventEmitter], which depending on [isAsync], * delivers events synchronously or asynchronously. */ constructor(isAsync?: boolean); emit(value: T): void; /** * @deprecated - use .emit(value) instead */ next(value: any): void; subscribe(generatorOrNext?: any, error?: any, complete?: any): any; } In Official Angular 2 Typescript definition, seems it has no way to mute or unsubscribe from EventEmitter. I got callback over time as pages use the same EventEmitter EventEmitter extends Subject. When you subscribe

How to use Flux and event emitter with .net MVC?

梦想的初衷 提交于 2019-11-30 15:40:04
问题 I am trying to learn the Flux pattern. I learned to use React with .net MVC and rendered it server side. I would like to learn Flux but all tutorials use node js. I don't use node. I don't know how to implement the Event Emitter part because it uses a node function. https://www.codementor.io/reactjs/tutorial/react-js-flux-architecture-tutorial About a 1/3 of the way down: "Event Emitter – The event emitter is responsible for notifying subscribers after a store has completed any data action.

How to use Flux and event emitter with .net MVC?

断了今生、忘了曾经 提交于 2019-11-30 14:21:24
I am trying to learn the Flux pattern. I learned to use React with .net MVC and rendered it server side. I would like to learn Flux but all tutorials use node js. I don't use node. I don't know how to implement the Event Emitter part because it uses a node function. https://www.codementor.io/reactjs/tutorial/react-js-flux-architecture-tutorial About a 1/3 of the way down: "Event Emitter – The event emitter is responsible for notifying subscribers after a store has completed any data action. Conversely, it also needs to be able to register observers for specific events. We’re going to be using

How do you share an EventEmitter in node.js?

时间秒杀一切 提交于 2019-11-30 08:22:09
I want to emit events from one file/module/script and listen to them in another file/module/script. How can I share the emitter variable between them without polluting the global namespace? Thanks! You can pass arguments to require calls thusly: var myModule = require('myModule')(Events) And then in "myModule" module.exports = function(Events) { // Set up Event listeners here } With that said, if you want to share an event emitter, create an emitter object and then pass to your "file/module/script" in a require call. Update: Though correct, this is a code smell as you are now tightly coupling

Golang events: EventEmitter / dispatcher for plugin architecture

余生长醉 提交于 2019-11-30 05:05:51
In Node.js I was able to make a WordPress clone rather easily using the EventEmitter to replicate and build a hooks-system into the CMS core, which plugins could then attach to. I now need this same level of extensibility and core isolation for my CMS written in and ported to Go. Basically I have the core finished now, but in order to make it truly flexible I have to be able to insert events (hooks) and to have plugins attach to these hooks with additional functionality. I don't care about recompiling (dynamic / static linking), as long as you don't have to modify the core to load plugins -