eventemitter

Angular 2 EventEmitter - Broadcasting next( … ) from a Service function

拈花ヽ惹草 提交于 2019-12-06 06:21:13
问题 To my understanding, the .toRx().subscribe( ... ) function is meant to RECEIVE messages and the .next() function is meant to BROADCAST messages In this plnkr ( http://plnkr.co/edit/MT3xOB?p=info ) , you invoke the .toRx().subscribe( ... ) function from a data object that seems to be defined/derived originally from the template: @Component({ selector : 'child-cmp', template : '', inputs : ['data'] }) class ChildCmp { afterViewInit() { this.data.toRx().subscribe((data) => { console.log('New

How to make an EventEmitter listen to another EventEmitter in Node.js?

家住魔仙堡 提交于 2019-12-05 14:29:21
I want to do something like this: var events = require("events"); var emitterA = new events.EventEmitter(); var emitterB = new events.EventEmitter(); emitterA.addListener("testA", function(){ console.log("emitterA detected testA"); }); emitterB.addListener("testA", function(){ console.log("emitterB detected testA"); }); emitterA.emit("testA"); And the output to be this: emitterA detected testA emitterB detected testA But when I run this code, the output I get is: emitterA detected testA I basically want one emitter to listen to events emitted by another emitter. The Rationale: I'm writing a

Angular 4 emitting and subscribing to an event in a shared service

坚强是说给别人听的谎言 提交于 2019-12-05 08:53:44
I am emitting an event in my main component: main.component.ts this.sharedService.cartData.emit(this.data); Here is my sharedService.ts import { Component, Injectable, EventEmitter } from '@angular/core'; export class SharedService { cartData = new EventEmitter<any>(); } In my other (Sub) Component, I want to access this value, but somehow, the subscription does not work: dashboard.ts private myData: any; constructor(private sharedService: SharedService) { this.sharedService.cartData.subscribe( (data: any) => myData = data, error => this.errorGettingData = <any>error, () => this.aggregateData

How to document an event emitter returned

不想你离开。 提交于 2019-12-05 07:51:30
How to document the events emitted by stream returned in MyFunc() with JSDoc? /** * [MyFunc description] * @param {Object} opts - [description] * @return {Stream} - [description] */ function MyFunc (opts) { // stream is an EventEmitter var stream = new MyEventEmitter(); stream.emit('event1', ... ); stream.emit('event2', ... ); return stream; } Jasmine Hegman You can document these behaviors by documenting your events ( event1 , event2 , ...) as @event MyFunc#event1 and MyFunc, or whoever does the emitting, with @fires MyFunc#event1 . You can also document functions that listen to those events

node.js event listener in another source file

别说谁变了你拦得住时间么 提交于 2019-12-05 05:15:24
I am trying to design a scenario where on a particular event getting triggered, I wanted a few listeners to perform some task. Trying to also manage S.R.P of code, I want to have the listeners in a different source file. I want to know if this is possible using event Emitter. Does event emitter only work on a single source file? var events = require('events'); var em = new events.EventEmitter(); exports.saveScheme = function (req, res) { var dal = dalFactory.createDAL(constants.SCHEME); return new Promise.resolve(dal.PromiseSave(req.body)) .then(function(data){ var schemeId = data._id; em

node.js eventEmitter + http.request

有些话、适合烂在心里 提交于 2019-12-05 00:11:40
问题 i did this tutorial node.js eventEmitter, it worked nicely. I added a method that uses http.request to get data, which works and emit the data. the problem is that the listener doesn't catch the event ! can someone help ? code : var events = require('events'); var util = require('util'); var http = require('http'); //http request options, it query the twitter api and get the public timeline, works! var options = { hostname : 'api.twitter.com', port : 80, method : 'get', path : '/1/statuses

Use EventEmitter in ES6 class

冷暖自知 提交于 2019-12-04 22:35:45
I am trying to get the EventEmitter in my own class running in ES6: "use strict"; const EventEmitter = require('events'); class Client extends EventEmitter{ constructor(token, client_id, client_secret, redirect_uri, code){ super(); this.token = token; this.client_id = client_id; this.client_secret = client_secret; this.redirect_uri = redirect_uri; this.code = code; } eventTest(){ this.emit("event"); console.log(this.token); } } let testClient = new Client(1,2,3,4,5); testClient.eventTest(); testClient.on('event', () => {console.log('triggerd!')} ); but the event is doing nothing ^^ Without ES6

Angular 4: `ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked

ぃ、小莉子 提交于 2019-12-04 16:28:03
问题 Every EventEmiiter in my child module gives this error and I can't find a fix for this. ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'true'. Current value: 'false'. This is what triggers my EventEmitter: ngOnChanges(changes: any) { if (changes.groupingTabValid) { if (changes.groupingTabValid.currentValue !== changes.groupingTabValid.previousValue) { this.groupingTabValidChange.emit(this.groupingTabValid); } } } Here is my "main"

Angular 2 EventEmitter - Broadcasting next( … ) from a Service function

最后都变了- 提交于 2019-12-04 10:14:08
To my understanding, the .toRx().subscribe( ... ) function is meant to RECEIVE messages and the .next() function is meant to BROADCAST messages In this plnkr ( http://plnkr.co/edit/MT3xOB?p=info ) , you invoke the .toRx().subscribe( ... ) function from a data object that seems to be defined/derived originally from the template: @Component({ selector : 'child-cmp', template : '', inputs : ['data'] }) class ChildCmp { afterViewInit() { this.data.toRx().subscribe((data) => { console.log('New data has arrived!', data); }); } } In this plnkr ( http://plnkr.co/edit/rNdInA?p=preview ) , you invoke

node.js eventEmitter + http.request

有些话、适合烂在心里 提交于 2019-12-03 14:48:23
i did this tutorial node.js eventEmitter , it worked nicely. I added a method that uses http.request to get data, which works and emit the data. the problem is that the listener doesn't catch the event ! can someone help ? code : var events = require('events'); var util = require('util'); var http = require('http'); //http request options, it query the twitter api and get the public timeline, works! var options = { hostname : 'api.twitter.com', port : 80, method : 'get', path : '/1/statuses/public_timeline.json?count=3&include_entities=true' } // The Thing That Emits Event Eventer = function()